getting subpixel with MatchTemplate

asked 2014-03-08 20:16:30 -0500

GrumbleLion gravatar image

updated 2014-04-28 14:20:34 -0500

I am working on a project that uses matchTemplate and I need sub pixel accuracy and I figure I could share the resulting code.

I've found others asking the same question, but the direction I am going is different since a general curve fit will not work since the values past the top few are not stable. So the plan is to scan out and find the smallest drop and then... edit: I am thinking that a parabola fit will work better.

Another problem is that if the template has a lot of fine detail the result will also not be stable. There are two options; option one: upsize both the template and the source image by two before match template. option two: shift the template by .5 pixel and weave those results into every other row/col of the heat map.

given the different methods I am wondering if something like this would be good.

minMaxLocSubPix(

in Mat = heat map. also gives function size of source.

in point = x,y point from minMaxLoc or any other point you want to explore

    in Polarity = Let this function know if we want large or small values

in Method = what algorithm to use since mine won't be the best for every application.

out Float x,y ) returns float error value if math result is limited to prevent moving more than one pixel.

See also this post I found http://answers.opencv.org/question/5584/find-max-with-sub-accuracy/

Here is my current code. Edit: 4/28/2014 I found a bug and updated it. http://www.longrange.net/Temp/CV_SubPix.h http://www.longrange.net/Temp/CV_SubPix.cpp

In summary: My question is... how do I add it to the library to share with others?

edit retag flag offensive close merge delete

Comments

well,you can find opencv source code,in c++ format you can add CV_EXPORTS ,in C format you can add CVAPI() to export your code.

wuling gravatar imagewuling ( 2014-04-28 19:08:48 -0500 )edit
1

The code CV_SubPix.cpp and CV_SubPix.h are not available now, could you please share them again?

winstones gravatar imagewinstones ( 2019-03-25 03:56:39 -0500 )edit