学习opencv——课后题8-4,检测图像的最大闭合轮廓长度是多少,面积
//习题8-4图像的最大闭合轮廓长度,面积,有点小问题,知道的高手指点一下
//#include <cv.h>
//#include <opencv2/legacy/legacy.hpp>
//#include <stdio.h>
//#include <stdlib.h>
//#include "highgui.h"
//using namespace std;
//using namespace cv;
//
//int main( int argc, char** argv )
//{
// CvMemStorage* storage_ct = cvCreateMemStorage(0);
// IplImage* img = cvLoadImage("tu6-9.jpg", CV_LOAD_IMAGE_GRAYSCALE);
//
// cvNamedWindow( "image" );
// cvShowImage( "image", img );
// IplImage* img_threshold=cvCreateImage(cvGetSize(img),img->depth,1);
// cvThreshold(img,img_threshold,100,255,CV_THRESH_BINARY);
//
// CvSeq* contours = 0;
// //double t1=(double)cvGetTickCount();
// cvFindContours( img_threshold, storage_ct, &contours, sizeof(CvContour),
// CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE );
// //多边形逼近
// contours = cvApproxPoly( contours, sizeof(CvContour), storage_ct, CV_POLY_APPROX_DP, 3, 1 );
//
// //double t2=(double)cvGetTickCount();
// //printf("run time:\n",(t2-t1)*1000/(cvGetTickFrequency()));
//
// printf("found %d Contours \n", contours->total );
// //长度
// double len=cvArcLength(contours,CV_WHOLE_SEQ,1);
// printf("contour's length is %lf\n",len);
// //面积
// double are=fabs(cvContourArea(contours,CV_WHOLE_SEQ));
// printf("contour's area is %lf\n",are);
//
// cvZero(img);
// cvDrawContours(img,contours,cvScalarAll(255),cvScalarAll(200),100);
// cvNamedWindow( "contours" );
// cvShowImage( "contours", img );
// cvWaitKey(0);
// cvReleaseMemStorage( &storage_ct );
// cvReleaseImage( &img );
// return 0;
//}

浙公网安备 33010602011771号