Updated samples using new cmd parser

pull/13383/head
itsyplen 13 years ago
parent c9ed7fee34
commit 49fb4ecbc1
  1. 59
      samples/cpp/camshiftdemo.cpp
  2. 43
      samples/cpp/chamfer.cpp

@ -8,24 +8,6 @@
using namespace cv; using namespace cv;
using namespace std; using namespace std;
void help()
{
cout << "\nThis is a demo that shows mean-shift based tracking\n"
<< "You select a color objects such as your face and it tracks it.\n"
<< "This reads from video camera (0 by default, or the camera number the user enters\n"
<< "Call:\n"
<< "\n./camshiftdemo [camera number]"
<< "\n" << endl;
cout << "\n\nHot keys: \n"
"\tESC - quit the program\n"
"\tc - stop the tracking\n"
"\tb - switch to/from backprojection view\n"
"\th - show/hide object histogram\n"
"\tp - pause video\n"
"To initialize tracking, select the object with mouse\n" << endl;
}
Mat image; Mat image;
bool backprojMode = false; bool backprojMode = false;
@ -63,31 +45,52 @@ void onMouse( int event, int x, int y, int, void* )
} }
} }
void help()
{
printf("\nThis is a demo that shows mean-shift based tracking\n"
"You select a color objects such as your face and it tracks it.\n"
"This reads from video camera (0 by default, or the camera number the user enters\n"
"Usage: \n"
" ./camshiftdemo [camera number]\n");
printf("\n\nHot keys: \n"
"\tESC - quit the program\n"
"\tc - stop the tracking\n"
"\tb - switch to/from backprojection view\n"
"\th - show/hide object histogram\n"
"\tp - pause video\n"
"To initialize tracking, select the object with mouse\n");
}
const char* keys =
{
"{1| | 0 | camera number}"
};
int main( int argc, char** argv ) int main( int argc, const char** argv )
{ {
help();
VideoCapture cap; VideoCapture cap;
Rect trackWindow; Rect trackWindow;
RotatedRect trackBox; RotatedRect trackBox;
int hsize = 16; int hsize = 16;
float hranges[] = {0,180}; float hranges[] = {0,180};
const float* phranges = hranges; const float* phranges = hranges;
CommandLineParser parser(argc, argv, keys);
if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) int camNum = parser.get<int>("1");
cap.open(argc == 2 ? argv[1][0] - '0' : 0);
else if( argc == 2 ) cap.open(camNum);
cap.open(argv[1]);
if( !cap.isOpened() ) if( !cap.isOpened() )
{ {
help(); help();
cout << "***Could not initialize capturing...***\n"; printf("***Could not initialize capturing...***\n");
return 0; printf("Current parameter's value: \n");
parser.printParams();
return -1;
} }
help();
namedWindow( "Histogram", 0 ); namedWindow( "Histogram", 0 );
namedWindow( "CamShift Demo", 0 ); namedWindow( "CamShift Demo", 0 );
setMouseCallback( "CamShift Demo", onMouse, 0 ); setMouseCallback( "CamShift Demo", onMouse, 0 );

@ -2,36 +2,45 @@
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp" #include "opencv2/contrib/contrib.hpp"
#include <iostream>
using namespace cv; using namespace cv;
using namespace std; using namespace std;
void help() void help()
{ {
cout <<
"\nThis program demonstrates Chamfer matching -- computing a distance between an \n" printf("\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" "Usage: \n"
"./chamfer <image edge map> <template edge map>," "./chamfer <image edge map> <template edge map>,"
" By default the inputs are logo_in_clutter.png logo.png\n" << endl; " By default the inputs are logo_in_clutter.png logo.png\n");
return;
} }
const char* keys =
{
"{1| |logo_in_clutter.png|image edge map }"
"{2| |logo.png |template edge map}"
};
int main( int argc, char** argv ) int main( int argc, const char** argv )
{ {
if( argc != 3 )
{
help();
return 0;
}
Mat img = imread(argc == 3 ? argv[1] : "logo_in_clutter.png", 0); help();
CommandLineParser parser(argc, argv, keys);
string image = parser.get<string>("1");
string templ = parser.get<string>("2");
Mat img = imread(image.c_str(), 0);
Mat tpl = imread(templ.c_str(), 0);
if (img.empty() || tpl.empty())
{
printf("Could not read image file %s or %s \n", image.c_str(), templ.c_str());
return -1;
}
Mat cimg; Mat cimg;
cvtColor(img, cimg, CV_GRAY2BGR); 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, // 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
@ -45,8 +54,8 @@ 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 << "matching not found\n"; printf("matching not found\n");
return 0; return -1;
} }
size_t i, n = results[best].size(); size_t i, n = results[best].size();

Loading…
Cancel
Save