我正在尝试用iPhone相机检测名片的边缘(并绘制它们),使用openCV。我对这个框架以及计算机视觉( Computer )或C++都很陌生。
我正在尝试使用这里解释的解决方案:https://stackoverflow.com/a/14123682/3708095,哪个github项目是https://github.com/foundry/OpenCVSquares
它适用于预定义的图像,但我试图让它与相机一起工作。
为此,我使用CvVideoCameraDelegate protocol
在CVViewController.mm
中实现它,就像它们在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 (也不熟悉)……
发布于 2014-12-03 20:16:31
所以解决办法其实很简单..。
与尝试使用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
https://stackoverflow.com/questions/27181068
复制相似问题