#include<iostream>
#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("i2.jpg");
Mat gray;
cvtColor(img, gray, CV_BGR2GRAY);
threshold(gray, img, 0, 255, THRESH_OTSU);
Mat dstimg = Mat::zeros(img.rows, img.cols, CV_8UC3);
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
findContours(img, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE); //CV_RETR_EXTERNAL
int index = 0;
Scalar color(255,0,0);
drawContours(dstimg, contours, -1, color);
imshow("dstimg", dstimg);
waitKey(30);
system("pause");
return 0;
#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("i2.jpg");
Mat gray;
cvtColor(img, gray, CV_BGR2GRAY);
threshold(gray, img, 0, 255, THRESH_OTSU);
Mat dstimg = Mat::zeros(img.rows, img.cols, CV_8UC3);
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
findContours(img, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE); //CV_RETR_EXTERNAL
int index = 0;
Scalar color(255,0,0);
drawContours(dstimg, contours, -1, color);
imshow("dstimg", dstimg);
waitKey(30);
system("pause");
return 0;
}