我正在尝试使用 iPhone 相机使用 openCV 检测名片的边缘(并绘制它们)。我是这个框架以及计算机视觉或 C++ 的新手。
我正在尝试使用此处解释的解决方案:https://stackoverflow.com/a/14123682/3708095 ,哪个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 做类似事情的教程或示例。 (也不熟悉)...
最佳答案
所以解决方案其实很简单......
与其尝试使用 matImage
设置 imageView.image
,它只需要将 matImage
转换为在 imageView 中实际修改因为 CvVideoCamera 已经用 imageView 初始化(并链接到):
self.videoCamera = [[CvVideoCamera alloc]initWithParentView:self.imageView];
最后的功能是这样的:
#ifdef __cplusplus
-(void)processImage:(cv::Mat &)matImage
{
matImage = CVSquares::detectedSquaresInImage(matImage, self.angleTolerance, self.threshold, self.levels, self.accuracy);
}
#endif
关于iOS 使用 openCV 从相机检测矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27181068/