使用AV SampleBuffer输出和面部检测的iPhone和OpenCV错误

| 嗨,Stack Overflow编码人员, 我最近一直在使用iPhone上的OpenCV,但遇到了麻烦,因此向您寻求帮助。我熟悉UIKit,Objective C,并使用OpenCV进行台式机上的Openframeworks C ++框架进行斑点检测和面部跟踪。 我目前正在尝试使用实时视频流进行人脸跟踪。 我已经从本教程中获得了人脸检测功能,并使用了一个图像来获得示例代码: http://niw.at/articles/2009/03/14/using-opencv-on-iphone/en 并且我已经从OpenGL和教程代码示例代码(以及Apple的示例)中成功地从OpenGL在窗口中显示的视频缓冲区输出中获取了数据,我现在实际上找不到该链接(将尽快发布)我可以找到它)。 通过从didOutputSampleBuffer创建IPLImage并使用标准的openCVEdgeDetect并在屏幕上显示,我设法使用视频缓冲区输出来获取与iPhone一起使用的视频流的edgeDetection。 但是我无法进行人脸检测,我已经尝试了很多次,但是都卡住了。目前,我只是想从传递到标准openCVFaceDetect方法的样本缓冲区中获取单个图像,然后在脸部周围用正方形(或任何标记)显示该图像。一旦能够正常工作,我将尝试完整的视频流。 使应用程序崩溃的函数正在传递IPLImage,然后执行openCV魔术,然后将此图像传递给委托函数以进行显示等
- (void) opencvFaceDetect:(IplImage *)aTempOverlayImage  {
cvSetErrMode(CV_ErrModeParent);

IplImage *aOverlayImage = aTempOverlayImage;//[self CreateIplImageFromUIImage:imageView.image];

// Scaling down
IplImage *small_image = cvCreateImage(cvSize(aOverlayImage->width/2,aOverlayImage->height/2), IPL_DEPTH_8U, 3);
cvPyrDown(aOverlayImage, small_image,CV_GAUSSIAN_5x5);


    // Load XML
NSString *path = [[NSBundle mainBundle] pathForResource:@\"haarcascade_frontalface_default\" ofType:@\"xml\"];
CvHaarClassifierCascade* cascade = (CvHaarClassifierCascade*)cvLoad([path cStringUsingEncoding:NSASCIIStringEncoding], NULL, NULL, NULL);
CvMemStorage* storage = cvCreateMemStorage(0);

// Detect faces and draw rectangle on them
CvSeq* faces = cvHaarDetectObjects(small_image, cascade, storage, 1.2f, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(20, 20));
cvReleaseImage(&small_image);
[self.delegate parseOpenCVFaces:faces];

// Create canvas to show the results
CGImageRef imageRef = [self getCGImageFromCVImage:aOverlayImage];//imageViewFromOpenCV.image.CGImage;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef contextRef = CGBitmapContextCreate(NULL, 360, 480,
                                                8, 480 * 4,
                                                colorSpace, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault);
CGContextDrawImage(contextRef, CGRectMake(0, 0, 360, 480), imageRef);

CGContextSetLineWidth(contextRef, 4);
CGContextSetRGBStrokeColor(contextRef, 0.0, 0.0, 1.0, 0.5);
int scale = 2;
// Draw results on the iamge
for(int i = 0; i < faces->total; i++) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    // Calc the rect of faces
    CvRect cvrect = *(CvRect*)cvGetSeqElem(faces, i);
    CGRect face_rect = CGContextConvertRectToDeviceSpace(contextRef, CGRectMake(cvrect.x * scale, cvrect.y * scale, cvrect.width * scale, cvrect.height * scale));

    CGContextStrokeRect(contextRef, face_rect);
    [pool release];
}

imageViewFromOpenCV.image = [UIImage imageWithCGImage:CGBitmapContextCreateImage(contextRef)];
[self.delegate parseOpenCVFaceImage:imageViewFromOpenCV.image];
CGContextRelease(contextRef);
CGColorSpaceRelease(colorSpace);

cvReleaseMemStorage(&storage);
cvReleaseHaarClassifierCascade(&cascade);
} 我收到以下错误:线程1:行上的
Program received signal:\"SIGABRT\"
cvPyrDown(aOverlayImage, small_image,CV_GAUSSIAN_5x5);
我看过openCV源代码,似乎该代码在分析之前会缩小并模糊图像。尽管我希望有更多知识的人提供更好的解释(我已经做过许多Google搜索)。当我注释掉这段代码时,在函数的右括号中出现了另一个类似的错误。 我要这样做正确吗?我知道人们已经在做这个工作,还有很多其他人希望在此方面有所帮助。任何建议或帮助,将不胜感激。 谢谢。     
已邀请:

要回复问题请先登录注册