Help and parsing command line were updated in next samples: chamfer

This commit is contained in:
itsyplen 2011-06-09 09:41:31 +00:00
parent a1ee9d406e
commit 4d417ccf7a
2 changed files with 31 additions and 23 deletions

View File

@ -3,7 +3,7 @@
#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
#include <iostream> //#include <iostream>
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
@ -78,16 +78,12 @@ int main( int argc, const char** argv )
float hranges[] = {0,180}; float hranges[] = {0,180};
const float* phranges = hranges; const float* phranges = hranges;
// if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
// cap.open(argc == 2 ? argv[1][0] - '0' : 0);
// else if( argc == 2 )
// cap.open(argv[1]);
cap.open(cameraInd); cap.open(cameraInd);
if( !cap.isOpened() ) if( !cap.isOpened() )
{ {
help(); help();
cout << "***Could not initialize capturing...***\n"; printf("***Could not initialize capturing...***\n");
return 0; return 0;
} }

View File

@ -2,33 +2,45 @@
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp" #include "opencv2/contrib/contrib.hpp"
#include <iostream> #include <stdio.h>
using namespace cv; using namespace cv;
using namespace std; using namespace std;
void help() void help()
{ {
cout << printf("\nThis program demonstrates Chamfer matching -- computing a distance between an \n"
"\nThis program demonstrates Chamfer matching -- computing a distance between an \n" "edge template and a query edge image.\n"
"edge template and a query edge image.\n" "Usage:\n"
"Call:\n" "./chamfer [<image edge map, logo_in_clutter.png as default>\n"
"./chamfer [<image edge map> <template edge map>]\n" "<template edge map, logo.png as default>]\n"
"By default\n" "Example: \n"
"the inputs are ./chamfer logo_in_clutter.png logo.png\n"<< endl; " ./chamfer logo_in_clutter.png logo.png\n");
} }
int main( int argc, char** argv ) int main( int argc, const char** argv )
{ {
if( argc != 1 && argc != 3 ) help();
{
help(); CommandLineParser parser(argc, argv);
return 0;
} string image = parser.get<string>("0","logo_in_clutter.png");
Mat img = imread(argc == 3 ? argv[1] : "logo_in_clutter.png", 0); string tempLate = parser.get<string>("1","logo.png");
Mat img = imread(image,0);
Mat cimg; Mat cimg;
cvtColor(img, cimg, CV_GRAY2BGR); cvtColor(img, cimg, CV_GRAY2BGR);
Mat tpl = imread(argc == 3 ? argv[2] : "logo.png", 0); Mat tpl = imread(tempLate,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( argc != 1 && argc != 3 )
// {
// help();
// return 0;
// }
// if the image and the template are not edge maps but normal grayscale images, // 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 // you might want to uncomment the lines below to produce the maps. You can also
// run Sobel instead of Canny. // run Sobel instead of Canny.
@ -41,7 +53,7 @@ int main( int argc, char** argv )
int best = chamerMatching( img, tpl, results, costs ); int best = chamerMatching( img, tpl, results, costs );
if( best < 0 ) if( best < 0 )
{ {
cout << "not found;\n"; printf("not found;\n");
return 0; return 0;
} }