OpenCV3 图像轮廓

参考并修改:

http://blog.csdn.net/guduruyu/article/details/69220296


#include "stdafx.h"

#include "opencv2/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"  


using namespace cv;
using namespace std;
int main()
{
Mat image_gray = imread("../mk.jpg", IMREAD_GRAYSCALE);
Mat image_binary;


threshold(image_gray, image_binary, 100, 255,THRESH_BINARY);
vector< vector<Point> > contours;
findContours(
image_binary,
contours,
noArray(),
RETR_LIST,
CHAIN_APPROX_SIMPLE
);
image_binary = Scalar::all(0);
drawContours(image_binary, contours, -1, Scalar::all(255));


imshow("gray image", image_gray);
imshow("Contours", image_binary);


waitKey(0);
 
return 0;

}

OpenCV3 图像轮廓