From 004a1cd64a1eff6db086421651c95b995a5672f2 Mon Sep 17 00:00:00 2001 From: LaurentBerger Date: Sat, 6 Jan 2018 21:44:47 +0100 Subject: [PATCH] Merge pull request #10529 from LaurentBerger:ExampleGoogleNet * Add a parameter labels to command line * default value * samples: caffe_googlenet.cpp minor refactoring --- samples/dnn/caffe_googlenet.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/samples/dnn/caffe_googlenet.cpp b/samples/dnn/caffe_googlenet.cpp index c1f0191948..08195ef2f6 100644 --- a/samples/dnn/caffe_googlenet.cpp +++ b/samples/dnn/caffe_googlenet.cpp @@ -60,7 +60,7 @@ static void getMaxClass(const Mat &probBlob, int *classId, double *classProb) *classId = classNumber.x; } -static std::vector readClassNames(const char *filename = "synset_words.txt") +static std::vector readClassNames(const char *filename ) { std::vector classNames; @@ -87,6 +87,7 @@ const char* params = "{ help | false | Sample app for loading googlenet model }" "{ proto | bvlc_googlenet.prototxt | model configuration }" "{ model | bvlc_googlenet.caffemodel | model weights }" + "{ label | synset_words.txt | names of ILSVRC2012 classes }" "{ image | space_shuttle.jpg | path to image file }" "{ opencl | false | enable OpenCL }" ; @@ -106,6 +107,7 @@ int main(int argc, char **argv) String modelTxt = parser.get("proto"); String modelBin = parser.get("model"); String imageFile = parser.get("image"); + String classNameFile = parser.get("label"); Net net; try { @@ -113,7 +115,7 @@ int main(int argc, char **argv) net = dnn::readNetFromCaffe(modelTxt, modelBin); //! [Read and initialize network] } - catch (cv::Exception& e) { + catch (const cv::Exception& e) { std::cerr << "Exception: " << e.what() << std::endl; //! [Check that network was read successfully] if (net.empty()) @@ -169,7 +171,7 @@ int main(int argc, char **argv) //! [Gather output] //! [Print results] - std::vector classNames = readClassNames(); + std::vector classNames = readClassNames(classNameFile.c_str()); std::cout << "Best class: #" << classId << " '" << classNames.at(classId) << "'" << std::endl; std::cout << "Probability: " << classProb * 100 << "%" << std::endl; //! [Print results]