getting subpixel with MatchTemplate
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?
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.
http://code.opencv.org/projects/opencv/wiki/How_to_contribute
The code CV_SubPix.cpp and CV_SubPix.h are not available now, could you please share them again?
use webarchive : https://web.archive.org/web/201709210...