错误:( - 27)NULL数组指针在函数cvGetMat中传递?

时间:2014-04-13 17:25:32

标签: c++ ios opencv

我是新手,打开简历。我试图找到带计数器的矩形时遇到问题。

这是我的完整代码。找到计数器并尝试获得积分

 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);
}

0 个答案:

没有答案