diff --git a/samples/cpp/dft.cpp b/samples/cpp/dft.cpp index 7d110ae04..ee1d9b165 100644 --- a/samples/cpp/dft.cpp +++ b/samples/cpp/dft.cpp @@ -2,31 +2,37 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" -#include +#include + using namespace cv; using namespace std; void help() { - cout << "\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; + 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" + "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("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; diff --git a/samples/cpp/distrans.cpp b/samples/cpp/distrans.cpp index cae24f5db..2cae7e754 100644 --- a/samples/cpp/distrans.cpp +++ b/samples/cpp/distrans.cpp @@ -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("1"); + gray = imread(filename.c_str(), 0); if(gray.empty()) { - help(); + 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); diff --git a/samples/cpp/drawing.cpp b/samples/cpp/drawing.cpp index 96dcce01e..3ff4714e3 100644 --- a/samples/cpp/drawing.cpp +++ b/samples/cpp/drawing.cpp @@ -1,14 +1,13 @@ #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" -#include +#include 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,9 +15,10 @@ static Scalar randomColor(RNG& rng) 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 DELAY = 5; int lineType = CV_AA; // change it to 8 to see non-antialiased graphics diff --git a/samples/cpp/edge.cpp b/samples/cpp/edge.cpp index c30b086ed..a76176ac9 100644 --- a/samples/cpp/edge.cpp +++ b/samples/cpp/edge.cpp @@ -1,20 +1,11 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" -#include +#include 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("1"); image = imread(filename, 1); if(image.empty()) { - help(); + 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);