1 #include "opencv2/imgproc/imgproc.hpp"
2 #include "opencv2/highgui/highgui.hpp"
3 #include "opencv2/contrib/contrib.hpp"
13 "\nThis program demonstrates Chamfer matching -- computing a distance between an \n"
14 "edge template and a query edge image.\n"
16 "./chamfer [<image edge map> <template edge map>]\n"
18 "the inputs are ./chamfer logo_in_clutter.png logo.png\n"<< endl;
20 int main( int argc, char** argv )
22 if( argc != 1 && argc != 3 )
27 Mat img = imread(argc == 3 ? argv[1] : "logo_in_clutter.png", 0);
29 cvtColor(img, cimg, CV_GRAY2BGR);
30 Mat tpl = imread(argc == 3 ? argv[2] : "logo.png", 0);
32 // if the image and the template are not edge maps but normal grayscale images,
33 // you might want to uncomment the lines below to produce the maps. You can also
34 // run Sobel instead of Canny.
36 // Canny(img, img, 5, 50, 3);
37 // Canny(tpl, tpl, 5, 50, 3);
39 vector<vector<Point> > results;
41 int best = chamerMatching( img, tpl, results, costs );
44 cout << "not found;\n";
48 size_t i, n = results[best].size();
49 for( i = 0; i < n; i++ )
51 Point pt = results[best][i];
52 if( pt.inside(Rect(0, 0, cimg.cols, cimg.rows)) )
53 cimg.at<Vec3b>(pt) = Vec3b(0, 255, 0);
55 imshow("result", cimg);