removed trailing backspaces, reduced number of warnings (under MSVC2010 x64) for size_t to int conversion, added handling of samples launch without parameters (should not have abnormal termination if there was no paramaters supplied)
This commit is contained in:
@@ -9,42 +9,46 @@ using namespace std;
|
||||
|
||||
void help()
|
||||
{
|
||||
cout <<
|
||||
"\nThis program demonstrates Chamfer matching -- computing a distance between an \n"
|
||||
"edge template and a query edge image.\n"
|
||||
"Call:\n"
|
||||
"./chamfer [<image edge map> <template edge map>]\n"
|
||||
"By default\n"
|
||||
"the inputs are ./chamfer logo_in_clutter.png logo.png\n"<< endl;
|
||||
cout <<
|
||||
"\nThis program demonstrates Chamfer matching -- computing a distance between an \n"
|
||||
"edge template and a query edge image.\n"
|
||||
"Usage:\n"
|
||||
"./chamfer <image edge map> <template edge map>,"
|
||||
" By default the inputs are logo_in_clutter.png logo.png\n" << endl;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
if( argc != 1 && argc != 3 )
|
||||
if( argc != 3 )
|
||||
{
|
||||
help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Mat img = imread(argc == 3 ? argv[1] : "logo_in_clutter.png", 0);
|
||||
Mat cimg;
|
||||
cvtColor(img, cimg, CV_GRAY2BGR);
|
||||
Mat tpl = imread(argc == 3 ? argv[2] : "logo.png", 0);
|
||||
|
||||
|
||||
// if the image and the template are not edge maps but normal grayscale images,
|
||||
// you might want to uncomment the lines below to produce the maps. You can also
|
||||
// run Sobel instead of Canny.
|
||||
|
||||
|
||||
// Canny(img, img, 5, 50, 3);
|
||||
// Canny(tpl, tpl, 5, 50, 3);
|
||||
|
||||
|
||||
vector<vector<Point> > results;
|
||||
vector<float> costs;
|
||||
int best = chamerMatching( img, tpl, results, costs );
|
||||
if( best < 0 )
|
||||
{
|
||||
cout << "not found;\n";
|
||||
cout << "matching not found\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
size_t i, n = results[best].size();
|
||||
for( i = 0; i < n; i++ )
|
||||
{
|
||||
@@ -52,7 +56,10 @@ int main( int argc, char** argv )
|
||||
if( pt.inside(Rect(0, 0, cimg.cols, cimg.rows)) )
|
||||
cimg.at<Vec3b>(pt) = Vec3b(0, 255, 0);
|
||||
}
|
||||
|
||||
imshow("result", cimg);
|
||||
|
||||
waitKey();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user