1. 例程
1 //轮廓寻找
2
3 #include "stdafx.h"
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11
12 using namespacestd;13 using namespacecv;14
15
16 voidmain()17 {18
19 Mat image = imread("03.jpg");20
21 Mat gray;22 cvtColor( image, gray, CV_RGB2GRAY);23
24 Mat binary;25 threshold( gray, binary, 150, 255, CV_THRESH_BINARY_INV);26
27 vector>contours;28 Mat binary_copy;29 binary.copyTo(binary_copy);30 findContours( binary_copy, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); //CV_RETR_EXTERNAL 获取外轮廓 CV_CHAIN_APPROX_NONE 获取每个轮廓的像素31
32 //遍历每一个轮廓,把多余的轮廓去掉
33 vector>::iterator it =contours.begin();34 while (it !=contours.end())35 {36 if (it->size() < 500)37 {38 it =contours.erase(it);39 }40 else</