我是新手,打开简历。我试图找到带计数器的矩形时遇到问题。
这是我的完整代码。找到计数器并尝试获得积分
IplImage* newimg = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
IplImage* cannyimg = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
IplImage* greyimg = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
IplImage* testimg = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
// convert the loaded image to a canny image
cvCvtColor(img, greyimg, CV_BGR2GRAY);
cvCanny(greyimg, cannyimg, 50, 150, 3);
// necessary to convert loaded image to an image with channel depth of 1
cvConvertImage(cannyimg, newimg);
cvConvertImage(img, testimg);
// allocate necessary memory to store the contours
CvMemStorage* storage = cvCreateMemStorage(0);
CvMemStorage* canny_storage = cvCreateMemStorage(0);
// find the contours in both the loaded image and the canny filtered image
cvFindContours(testimg, storage, &contours, sizeof(CvContour),
CV_RETR_EXTERNAL, CV_CHAIN_CODE);
cvFindContours(newimg, canny_storage, &canny_contours, sizeof(CvContour),
CV_RETR_EXTERNAL, CV_CHAIN_CODE);
for( CvSeq* c=canny_contours; c!=NULL; c=c->h_next)
{
CvRect Rects = cvBoundingRect( c );
NSLog(@"%d",Rects.x);
NSLog(@"%d",Rects.y);
NSLog(@"%d",Rects.width);
NSLog(@"%d",Rects.height);
}