学习opencv,课后习题8-5,
//习题8-5为什么一样呢
//#include <cv.h>
//#include <opencv2/legacy/legacy.hpp>
//#include <stdio.h>
//#include <stdlib.h>
//#include <iomanip>
//#include "highgui.h"
//using namespace std;
//using namespace cv;
//
//int main( int argc, char** argv )
//{
// CvMemStorage* storage_ct = cvCreateMemStorage(0);
// IplImage* img = cvLoadImage("8-5.jpg", CV_LOAD_IMAGE_GRAYSCALE);
// IplImage* img_thrshold=cvCreateImage(cvGetSize(img),img->depth,1);
// cvThreshold(img,img_thrshold,100,255,CV_THRESH_BINARY);
//
// cvNamedWindow( "image" );
// cvShowImage( "image", img );
//
// CvSeq* contours = 0;
// //double t1=(double)cvGetTickCount();
// cvFindContours( img_thrshold, storage_ct, &contours, sizeof(CvContour),
// CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE );
// //存取精度1/90,1/66,1/11,1/1
// double data[]={0.0111111,0.015151515,0.0909090,0.1};
// //多边形逼近
// for (int i=0;i<4;i++)
// {
// double d=data[i];
// cout<<"精度:"<<fixed<<setprecision(5)<<d<<": ";
// contours = cvApproxPoly( contours, sizeof(CvContour), storage_ct, CV_POLY_APPROX_DP,d,1);
// //长度
// 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号