From d3f8b2eeb76c4b1ca1040de240a1bc297b767bb3 Mon Sep 17 00:00:00 2001 From: itsyplen Date: Wed, 10 Aug 2011 12:33:03 +0000 Subject: [PATCH] Updated using new cmd parser --- samples/cpp/demhist.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/samples/cpp/demhist.cpp b/samples/cpp/demhist.cpp index cf48c25e3..9f524a892 100644 --- a/samples/cpp/demhist.cpp +++ b/samples/cpp/demhist.cpp @@ -56,22 +56,31 @@ void updateBrightnessContrast( int /*arg*/, void* ) } void help() { - cout << "\nThis program demonstrates the use of calcHist() -- histogram creation.\n" - "Call:\n" - "demhist [image_name -- Defaults to baboon.jpg]\n" << endl; + printf("\nThis program demonstrates the use of calcHist() -- histogram creation.\n" + "Usage: \n" + "demhist [image_name -- Defaults to baboon.jpg]\n"); } -int main( int argc, char** argv ) +const char* keys = { - // Load the source image. HighGUI use. - image = imread( argc == 2 ? argv[1] : "baboon.jpg", 0 ); + "{1| |baboon.jpg|input image file}" +}; + +int main( int argc, const char** argv ) +{ + help(); + + CommandLineParser parser(argc, argv, keys); + string inputImage = parser.get("1"); + + // Load the source image. HighGUI use. + image = imread( inputImage, 0 ); + if(image.empty()) + { + printf("Cannot read image file: %s\n", inputImage.c_str()); + return -1; + } - if( image.empty() ) - { - help(); - return -1; - } - help(); namedWindow("image", 0); namedWindow("histogram", 0);