Ask help for chamfer matching sample code
Hello, I got chamfermatching.cpp and sample code from OpenCV 2.4.9 and I am trying to make the algorithm to match characters. Please see my source files and testing images attached. I got below results:
The program can match e1.png in e2.png, minCost is 0.0626175. It can match e1.png in e1.png(match itself), minCost is 0.0730605. But it can also match e1.png in a.png, minCost is 0.0681643.
You see, this means the match is not good, it cannot distinguish letter a, letter e and bigger letter e. I did a little change to the code. Commenting or uncommenting Canny() lines in opencv_test.cpp has the similar results.
I doubt the problem is in the implementation of chamferMatching2() function. Its declaration is: CV_EXPORTS_W int chamferMatching2( Mat& img, Mat& templ, CV_OUT vector<vector<point> >& results, CV_OUT vector<float>& cost, double templScale=1, int maxMatches = 20, double minMatchDistance = 1.0, int padX = 3, int padY = 3, int scales = 5, double minScale = 0.6, double maxScale = 1.6, double orientationWeight = 0.5, double truncate = 20);
You see, there are a lot of default parameters. I doubt the problem exists here. Maybe I should adjust the default parameters? Can you give me some guide to fix the problem?
Thanks in advance!
chamfermatching2.cpp: http://pastebin.com/rKb1gKex
opencv_test.cpp: http://pastebin.com/7Xz0ef6s
I am using Windows 7 x64 system and VS 2010.
apart from the complications you're facing,
it sounds a bit like you're trying to do ocr there. can it be, that chamferMatching alone is to weak to do the job ? like, it's the wrong tool ?
Actually I have firstly tried ocr here, I found ocr is very unstable, it often performs wrong recognition. So I am trying to find some new tools/algorithms such as chamfer matching, shape context, etc. I read some papers, seems chamfer matching and shape context are very powerful to do text recognition. See http://mi.eng.cam.ac.uk/~bdrs2/papers/thayananthan_cvpr03.pdf So I am wondering if adjusting some parameters in samples of OpenCV chamfer matching algorithms can fit my work.
Have you solved the problem? I tried to run your program and it turns out the result is not the same as yours: e1 -> e1: 0.0730606, e1 -> e2: 0.0626175, e1 -> a: 0.138126. Can you double check your results? Btw, matching "a to e1" and "e1 to a" will give different scores due to the nature of Chamfer match.