我已经在我的 iphone 项目中实现了这个 OpenCV 构建:
http://aptogo.co.uk/2011/09/opencv-framework-for-ios/ 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,输出,1);
我不确定我做得是否正确。因为我没有在“输出”中得到像“MinMax”这样的结果来获取找到的匹配的位置...我是否将正确的变量传递给 matchTemplate 函数...?
无论如何,有人可以告诉我我做错了什么以及如何使这项工作有效吗?
- edit -
Added a screenshot of my variable 'output'
谢谢你的帮助!