1 #include <opencv2/core/utility.hpp>
2 #include "opencv2/imgproc.hpp"
3 #include "opencv2/highgui.hpp"
4 #include "opencv2/contrib.hpp"
14 cout << "\nThis program demonstrates Chamfer matching -- computing a distance between an \n"
15 "edge template and a query edge image.\n"
17 "./chamfer <image edge map> <template edge map>,"
18 " By default the inputs are logo_in_clutter.png logo.png\n";
23 "{@logo1 |logo_in_clutter.png |image edge map }"
24 "{@logo2 |logo.png |template edge map}"
27 int main( int argc, const char** argv )
31 CommandLineParser parser(argc, argv, keys);
33 string image = parser.get<string>(0);
34 string templ = parser.get<string>(1);
35 Mat img = imread(image.c_str(), 0);
36 Mat tpl = imread(templ.c_str(), 0);
38 if (img.empty() || tpl.empty())
40 cout << "Could not read image file " << image << " or " << templ << "." << endl;
44 cvtColor(img, cimg, COLOR_GRAY2BGR);
46 // if the image and the template are not edge maps but normal grayscale images,
47 // you might want to uncomment the lines below to produce the maps. You can also
48 // run Sobel instead of Canny.
50 // Canny(img, img, 5, 50, 3);
51 // Canny(tpl, tpl, 5, 50, 3);
53 vector<vector<Point> > results;
55 int best = chamerMatching( img, tpl, results, costs );
58 cout << "matching not found" << endl;
62 size_t i, n = results[best].size();
63 for( i = 0; i < n; i++ )
65 Point pt = results[best][i];
66 if( pt.inside(Rect(0, 0, cimg.cols, cimg.rows)) )
67 cimg.at<Vec3b>(pt) = Vec3b(0, 255, 0);
70 imshow("result", cimg);