CvMemStorage* storage1 = cvCreateMemStorage( 0 ); CvSeq* contour = NULL; IplImage *imgTemp = cvCloneImage( dilateImage ); cvFindContours( imgTemp, storage1, &contour, sizeof( CvContour ), CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE); int ContoursCount = 0; IplImage *TrangleImage = cvCloneImage(inTopView); int height =TrangleImage->height; int width =TrangleImage->width; int step =TrangleImage->widthStep; int channels=TrangleImage->nChannels; outCarSegment.CarRect.clear(); for( ; contour != NULL; contour = contour -> h_next) { CvRect rect = cvBoundingRect(contour, 0); if (rect.width > 20 && rect.height > 20) { cvRectangle( TrangleImage, cvPoint( rect.x, rect.y ),cvPoint( rect.x + rect.width, rect.y + rect.height ), CV_RGB(255,0,0), 1, 8, 0); ContoursCount++; outCarSegment.CarRect.push_back(rect); } } cvSaveImage("FindContours.png", TrangleImage);
我的这段例子只是取物体外边框,需要取物体内边框的可以参照找一篇文章:http://blog.csdn.net/honpey/article/details/8575507;