fname 为要分析图片的路径
IplImage* src = cvLoadImage(fname, CV_LOAD_IMAGE_GRAYSCALE);
IplImage* dst = cvCreateImage(cvGetSize(src), 8, 3);
IplImage *contoursImage = cvCreateImage(cvGetSize(src), 8, 1);
cvZero(contoursImage);
IplImage* dst = cvCreateImage(cvGetSize(src), 8, 3);
IplImage *contoursImage = cvCreateImage(cvGetSize(src), 8, 1);
cvZero(contoursImage);
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contour = 0;
cvThreshold(src, src, 120, 255, CV_THRESH_BINARY); // 二值化
// 提取轮廓
int contour_num = cvFindContours(src, storage, &contour, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
cvZero(dst); // 清空数组
CvSeq *_contour = contour;
double maxarea = 0;
double minarea = 100;
int m = 0;
for (; contour != 0; contour = contour->h_next)
{
double tmparea = fabs(cvContourArea(contour));
if (tmparea < minarea)
{ <
CvSeq* contour = 0;
cvThreshold(src, src, 120, 255, CV_THRESH_BINARY); // 二值化
// 提取轮廓
int contour_num = cvFindContours(src, storage, &contour, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
cvZero(dst); // 清空数组
CvSeq *_contour = contour;
double maxarea = 0;
double minarea = 100;
int m = 0;
for (; contour != 0; contour = contour->h_next)
{
double tmparea = fabs(cvContourArea(contour));
if (tmparea < minarea)
{ <