#include <iostream>
#include <opencv2\opencv.hpp>
#include <math.h>
using namespace cv;
using namespace std;
/*原图片*/
Mat src = imread("E:\\3.jpg");
Mat dst;
/*阈值*/
double threshold_value = 130;
RNG rng;
void Demo_Contours() {
vector<vector<Point>>contours;
vector<Vec4i>hierarchy;
/*Canny边缘检测*/
Canny(src, dst, threshold_value, threshold_value * 2, 3, false);
/*contours保存轮廓 hierarchy轮廓信息 RETR_TREE表示检测所有轮廓*/
findContours(dst, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));
Mat drawimg = Mat::zeros(dst.size(), CV_8UC3);
for (size_t i = 0; i < contours.size(); i++) {
Scalar color = Scalar(255, 0, 0);
drawContours(drawimg, contours, i, color, 2, LINE_8, hierarchy, 0, Point(0, 0));
}
imshow("output_img", drawimg);
}
int main()
{
Demo_Contours();
waitKey(0);
return 0;
}