【发布时间】:2011-11-08 10:33:57
【问题描述】:
我已经在我的 iphone 项目中实现了这个 OpenCV 构建:
http://aptogo.co.uk/2011/09/opencv-framework-for-ios/
它构建成功,我知道如何用我的相机捕捉图像,对其进行灰度化并在图像视图上显示。
但我想做的是将我(用相机)捕获的图像与模板图像进行模板匹配。
我将两张图像都进行了灰度化处理,但我只是不明白“matchTemplate”是如何工作的。这是我到目前为止所拥有的:
cv::Mat grayFrame, grayImg, output;
// This is the template image which i store in a cv::Mat and
// after that i grayscale the image
UIImage *testImage = [UIImage imageNamed:@"qr.png"];
cv::Mat tempMat = [testImage CVMat];
cv::cvtColor(tempMat, grayImg, cv::COLOR_RGB2GRAY);
// Convert captured frame to grayscale
cv::cvtColor(_lastFrame, grayFrame, cv::COLOR_RGB2GRAY);
// Having trouble here...
cv::matchTemplate(grayFrame, grayImg, output, CV_TM_CCORR_NORMED);
// Display result
// This already works for both the captured image and the template image
camView.image = [UIImage imageWithCVMat:grayFrame];
这段代码的问题是,是这一行吗:
cv::matchTemplate(grayFrame, grayImg, output, 1);
我不确定我是否做得对。因为我没有像“MinMax”那样在“输出”中得到结果来获取找到的匹配的位置......我什至将正确的变量传递给 matchTemplate 函数......??
无论如何,有人可以告诉我我做错了什么以及如何解决这个问题吗?
- 编辑- 添加了我的变量“输出”的屏幕截图
感谢您的帮助!
【问题讨论】:
标签: iphone xcode4 opencv computer-vision