#include
#include
#include
using namespace cv;
using namespace std;
int main()
{
system("color 1A");
Mat srcImage = imread("C:/Users/hasee-pc/Desktop/girl.jpg",0);
imshow("原始图", srcImage);
Mat dstImage = Mat::zeros(srcImage.rows, srcImage.cols, CV_8UC3);
srcImage = srcImage > 119;
imshow("取阈值后的原始图", srcImage);
vector > contours;
vector hierarchy;
findContours(srcImage, contours, hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
int index = 0;
for (; index >= 0; index = hierarchy[index][0])
{
Scalar color(rand() & 255, rand() & 255, rand()&255);
drawContours(dstImage, contours, index, color, FILLED, 8, hierarchy);
}
imshow("轮廓图",dstImage);
waitKey(0);
return 0;
}