我正在尝试使用OpenCV和iPhone相机检测商务卡的边缘并绘制它们。我对这个框架以及计算机视觉或C ++都很陌生。
我正在尝试使用在此处解释的解决方案:https://dev59.com/XGzXa4cB1Zd3GeqPR0rP#14123682。该GitHub项目为https://github.com/foundry/OpenCVSquares。
它可以用预定义的图像工作,但我试图让它与相机一起工作。
为此,我正在使用
我正在尝试使用在此处解释的解决方案:https://dev59.com/XGzXa4cB1Zd3GeqPR0rP#14123682。该GitHub项目为https://github.com/foundry/OpenCVSquares。
它可以用预定义的图像工作,但我试图让它与相机一起工作。
为此,我正在使用
CvVideoCameraDelegate protocol
,并在CVViewController.mm
中实现它,就像他们在http://docs.opencv.org/doc/tutorials/ios/video_processing/video_processing.html中所解释的那样:#ifdef __cplusplus
-(void)processImage:(cv::Mat &)matImage
{
//NSLog (@"Processing Image");
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
matImage = CVSquares::detectedSquaresInImage(matImage, self.tolerance, self.threshold, self.levels, [self accuracy]);
UIImage *image = [[UIImage alloc]initWithCVMat:matImage orientation:UIImageOrientationDown];
dispatch_async(dispatch_get_main_queue(), ^{
self.imageView.image = image;
});
});
}
#endif
编辑:
如果我这样做,会给我一个EXC_BAD_ACCESS错误...
如果我在处理之前克隆matImage,并记录它,它似乎可以处理图像,甚至找到矩形,但矩形没有绘制到输出到imageView的图像中。
cv::Mat temp = matImage.clone();
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIImage *image = [[UIImage alloc]CVSquares::detectedSquaresInImage(temp, self.tolerance, self.threshold, self.levels, [self accuracy])
orientation:UIImageOrientationDown];
dispatch_async(dispatch_get_main_queue(), ^{
self.imageView.image = image;
});
});
我相信我错过了一些东西,可能是因为我没有正确地传递某个对象、指向对象的指针等等,而且我需要修改的对象并没有被修改。
无论如何,如果这不是正确的方法,我会非常感激提供一个教程或示例,在其中他们做类似的事情,使用openCV或者GPUImage(我也不熟悉它)...