iphone opencv - template matching

六月ゝ 毕业季﹏ 提交于 2019-12-21 02:53:15

问题


i've implemented this OpenCV build into my iphone project:

http://aptogo.co.uk/2011/09/opencv-framework-for-ios/

It builds successfully and i know how to capture an image with my camera, grayscale it and show it on an imageview.

But what i'd like to do is templatematching with the image that i captured (with the camera) against an template image.

I have both images grayscaled, but i just don't get how the 'matchTemplate' works. This is what i have so far:

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];

The problem with this code is, is this line:

cv::matchTemplate(grayFrame, grayImg, output, 1);

I'm not sure if i'm doing it right. Because i don't get a result back in 'output' like "MinMax" to get the positions of the found match... Am i even passing the right variables to the matchTemplate function...??

Anyway, can someone please tell me what i'm doing wrong and how to make this work?

  • edit - Added a screenshot of my variable 'output'

Thanks for any help!


回答1:


The matchTemplate() function returns a matrix whose values represent the probability of the match on every pixel of the original image. It contains floating-point data and has the same size (width/height as the input). To extract the position of the most likely match, you must run the minMaxLoc() function over the result.



来源:https://stackoverflow.com/questions/8049066/iphone-opencv-template-matching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!