Update samples using cmd parser

This commit is contained in:
itsyplen 2011-08-11 06:46:09 +00:00
parent 1863f58a67
commit bc64567d37
4 changed files with 73 additions and 55 deletions

View File

@ -2,31 +2,37 @@
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
void help()
{
cout << "\nThis program demonstrated the use of the discrete Fourier transform (dft)\n"
printf("\nThis program demonstrated the use of the discrete Fourier transform (dft)\n"
"The dft of an image is taken and it's power spectrum is displayed.\n"
"Call:\n"
"./dft [image_name -- default lena.jpg]\n" << endl;
"Usage:\n"
"./dft [image_name -- default lena.jpg]\n");
}
int main(int argc, char ** argv)
const char* keys =
{
const char* filename = argc >=2 ? argv[1] : "lena.jpg";
"{1| |lena.jpg|input image file}"
};
Mat img = imread(filename, CV_LOAD_IMAGE_GRAYSCALE);
int main(int argc, const char ** argv)
{
help();
CommandLineParser parser(argc, argv, keys);
string filename = parser.get<string>("1");
Mat img = imread(filename.c_str(), CV_LOAD_IMAGE_GRAYSCALE);
if( img.empty() )
{
help();
printf("Cannot read image file: %s\n", filename.c_str());
return -1;
}
help();
int M = getOptimalDFTSize( img.rows );
int N = getOptimalDFTSize( img.cols );
Mat padded;

View File

@ -5,24 +5,6 @@
using namespace cv;
void help()
{
printf("\nProgram to demonstrate the use of the distance transform function between edge images.\n"
"Usage:\n"
"./distrans [image_name -- default image is stuff.jpg]\n"
);
printf( "\nHot keys: \n"
"\tESC - quit the program\n"
"\tC - use C/Inf metric\n"
"\tL1 - use L1 metric\n"
"\tL2 - use L2 metric\n"
"\t3 - use 3x3 mask\n"
"\t5 - use 5x5 mask\n"
"\t0 - use precise distance transform\n"
"\tv - switch Voronoi diagram mode on/off\n"
"\tSPACE - loop through all the modes\n" );
}
int maskSize0 = CV_DIST_MASK_5;
bool buildVoronoi = false;
int edgeThresh = 100;
@ -101,17 +83,41 @@ void onTrackbar( int, void* )
imshow("Distance Map", dist8u );
}
int main( int argc, char** argv )
void help()
{
char* filename = argc == 2 ? argv[1] : (char*)"stuff.jpg";
gray = imread(filename, 0);
printf("\nProgram to demonstrate the use of the distance transform function between edge images.\n"
"Usage:\n"
"./distrans [image_name -- default image is stuff.jpg]\n"
"\nHot keys: \n"
"\tESC - quit the program\n"
"\tC - use C/Inf metric\n"
"\tL1 - use L1 metric\n"
"\tL2 - use L2 metric\n"
"\t3 - use 3x3 mask\n"
"\t5 - use 5x5 mask\n"
"\t0 - use precise distance transform\n"
"\tv - switch Voronoi diagram mode on/off\n"
"\tSPACE - loop through all the modes\n\n");
}
const char* keys =
{
"{1| |stuff.jpg|input image file}"
};
int main( int argc, const char** argv )
{
help();
CommandLineParser parser(argc, argv, keys);
string filename = parser.get<string>("1");
gray = imread(filename.c_str(), 0);
if(gray.empty())
{
printf("Cannot read image file: %s\n", filename.c_str());
help();
return -1;
}
help();
namedWindow("Distance Map", 1);
createTrackbar("Brightness Threshold", "Distance Map", &edgeThresh, 255, onTrackbar, 0);

View File

@ -1,14 +1,13 @@
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <stdio.h>
using namespace cv;
void help()
{
std::cout
<< "\nThis program demonstrates OpenCV drawing and text output functions.\n"
"Call:\n"
"./drawing\n" << std::endl;
printf("\nThis program demonstrates OpenCV drawing and text output functions.\n"
"Usage:\n"
" ./drawing\n");
}
static Scalar randomColor(RNG& rng)
{
@ -16,8 +15,9 @@ static Scalar randomColor(RNG& rng)
return Scalar(icolor&255, (icolor>>8)&255, (icolor>>16)&255);
}
int main( int, char** )
int main()
{
help();
char wndname[] = "Drawing Demo";
const int NUMBER = 100;
const int DELAY = 5;

View File

@ -1,20 +1,11 @@
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
void help()
{
cout <<
"\nDemonstrate Canny edge detection\n"
"Call:\n"
"/.edge [image_name -- Default is fruits.jpg]\n" << endl;
}
int edgeThresh = 1;
Mat image, gray, edge, cedge;
@ -31,17 +22,32 @@ void onTrackbar(int, void*)
imshow("Edge map", cedge);
}
int main( int argc, char** argv )
void help()
{
char* filename = argc == 2 ? argv[1] : (char*)"fruits.jpg";
printf("\nThis sample demonstrates Canny edge detection\n"
"Call:\n"
" /.edge [image_name -- Default is fruits.jpg]\n\n");
}
const char* keys =
{
"{1| |fruits.jpg|input image name}"
};
int main( int argc, const char** argv )
{
help();
CommandLineParser parser(argc, argv, keys);
string filename = parser.get<string>("1");
image = imread(filename, 1);
if(image.empty())
{
printf("Cannot read image file: %s\n", filename.c_str());
help();
return -1;
}
help();
cedge.create(image.size(), image.type());
cvtColor(image, gray, CV_BGR2GRAY);