Ask help for chamfer matching sample code

asked 2014-08-12 20:21:10 -0600

unixer gravatar image

updated 2018-10-04 23:46:21 -0600

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!






edit retag flag offensive close merge delete


I am using Windows 7 x64 system and VS 2010.

unixer gravatar imageunixer ( 2014-08-12 20:56:00 -0600 )edit

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 ?

berak gravatar imageberak ( 2014-08-23 02:37:15 -0600 )edit

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 So I am wondering if adjusting some parameters in samples of OpenCV chamfer matching algorithms can fit my work.

unixer gravatar imageunixer ( 2014-08-23 19:52:34 -0600 )edit

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.

Icarus gravatar imageIcarus ( 2014-09-23 03:14:34 -0600 )edit