Commit bc64567d authored by itsyplen's avatar itsyplen

Update samples using cmd parser

parent 1863f58a
...@@ -2,31 +2,37 @@ ...@@ -2,31 +2,37 @@
#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
#include <iostream> #include <stdio.h>
using namespace cv; using namespace cv;
using namespace std; using namespace std;
void help() 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" "The dft of an image is taken and it's power spectrum is displayed.\n"
"Call:\n" "Usage:\n"
"./dft [image_name -- default lena.jpg]\n" << endl; "./dft [image_name -- default lena.jpg]\n");
} }
const char* keys =
{
"{1| |lena.jpg|input image file}"
};
int main(int argc, const char ** argv)
int main(int argc, char ** argv)
{ {
const char* filename = argc >=2 ? argv[1] : "lena.jpg"; help();
CommandLineParser parser(argc, argv, keys);
string filename = parser.get<string>("1");
Mat img = imread(filename, CV_LOAD_IMAGE_GRAYSCALE); Mat img = imread(filename.c_str(), CV_LOAD_IMAGE_GRAYSCALE);
if( img.empty() ) if( img.empty() )
{ {
help(); help();
printf("Cannot read image file: %s\n", filename.c_str());
return -1; return -1;
} }
help();
int M = getOptimalDFTSize( img.rows ); int M = getOptimalDFTSize( img.rows );
int N = getOptimalDFTSize( img.cols ); int N = getOptimalDFTSize( img.cols );
Mat padded; Mat padded;
......
...@@ -5,24 +5,6 @@ ...@@ -5,24 +5,6 @@
using namespace cv; 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; int maskSize0 = CV_DIST_MASK_5;
bool buildVoronoi = false; bool buildVoronoi = false;
int edgeThresh = 100; int edgeThresh = 100;
...@@ -101,17 +83,41 @@ void onTrackbar( int, void* ) ...@@ -101,17 +83,41 @@ void onTrackbar( int, void* )
imshow("Distance Map", dist8u ); imshow("Distance Map", dist8u );
} }
int main( int argc, char** argv ) 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"
"\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 =
{ {
char* filename = argc == 2 ? argv[1] : (char*)"stuff.jpg"; "{1| |stuff.jpg|input image file}"
gray = imread(filename, 0); };
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()) if(gray.empty())
{ {
help(); printf("Cannot read image file: %s\n", filename.c_str());
help();
return -1; return -1;
} }
help();
namedWindow("Distance Map", 1); namedWindow("Distance Map", 1);
createTrackbar("Brightness Threshold", "Distance Map", &edgeThresh, 255, onTrackbar, 0); createTrackbar("Brightness Threshold", "Distance Map", &edgeThresh, 255, onTrackbar, 0);
......
#include "opencv2/core/core.hpp" #include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
#include <iostream> #include <stdio.h>
using namespace cv; using namespace cv;
void help() void help()
{ {
std::cout printf("\nThis program demonstrates OpenCV drawing and text output functions.\n"
<< "\nThis program demonstrates OpenCV drawing and text output functions.\n" "Usage:\n"
"Call:\n" " ./drawing\n");
"./drawing\n" << std::endl;
} }
static Scalar randomColor(RNG& rng) static Scalar randomColor(RNG& rng)
{ {
...@@ -16,9 +15,10 @@ static Scalar randomColor(RNG& rng) ...@@ -16,9 +15,10 @@ static Scalar randomColor(RNG& rng)
return Scalar(icolor&255, (icolor>>8)&255, (icolor>>16)&255); return Scalar(icolor&255, (icolor>>8)&255, (icolor>>16)&255);
} }
int main( int, char** ) int main()
{ {
char wndname[] = "Drawing Demo"; help();
char wndname[] = "Drawing Demo";
const int NUMBER = 100; const int NUMBER = 100;
const int DELAY = 5; const int DELAY = 5;
int lineType = CV_AA; // change it to 8 to see non-antialiased graphics int lineType = CV_AA; // change it to 8 to see non-antialiased graphics
......
#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
#include <iostream> #include <stdio.h>
using namespace cv; using namespace cv;
using namespace std; 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; int edgeThresh = 1;
Mat image, gray, edge, cedge; Mat image, gray, edge, cedge;
...@@ -31,17 +22,32 @@ void onTrackbar(int, void*) ...@@ -31,17 +22,32 @@ void onTrackbar(int, void*)
imshow("Edge map", cedge); imshow("Edge map", cedge);
} }
int main( int argc, char** argv ) void help()
{
printf("\nThis sample demonstrates Canny edge detection\n"
"Call:\n"
" /.edge [image_name -- Default is fruits.jpg]\n\n");
}
const char* keys =
{ {
char* filename = argc == 2 ? argv[1] : (char*)"fruits.jpg"; "{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); image = imread(filename, 1);
if(image.empty()) if(image.empty())
{ {
help(); printf("Cannot read image file: %s\n", filename.c_str());
help();
return -1; return -1;
} }
help();
cedge.create(image.size(), image.type()); cedge.create(image.size(), image.type());
cvtColor(image, gray, CV_BGR2GRAY); cvtColor(image, gray, CV_BGR2GRAY);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment