@@ -60,7 +60,7 @@ static void getMaxClass(const Mat &probBlob, int *classId, double *classProb)
60
60
*classId = classNumber.x ;
61
61
}
62
62
63
- static std::vector<String> readClassNames (const char *filename = " synset_words.txt " )
63
+ static std::vector<String> readClassNames (const char *filename )
64
64
{
65
65
std::vector<String> classNames;
66
66
@@ -87,6 +87,7 @@ const char* params
87
87
= " { help | false | Sample app for loading googlenet model }"
88
88
" { proto | bvlc_googlenet.prototxt | model configuration }"
89
89
" { model | bvlc_googlenet.caffemodel | model weights }"
90
+ " { label | synset_words.txt | names of ILSVRC2012 classes }"
90
91
" { image | space_shuttle.jpg | path to image file }"
91
92
" { opencl | false | enable OpenCL }"
92
93
;
@@ -106,14 +107,15 @@ int main(int argc, char **argv)
106
107
String modelTxt = parser.get <string>(" proto" );
107
108
String modelBin = parser.get <string>(" model" );
108
109
String imageFile = parser.get <String>(" image" );
110
+ String classNameFile = parser.get <String>(" label" );
109
111
110
112
Net net;
111
113
try {
112
114
// ! [Read and initialize network]
113
115
net = dnn::readNetFromCaffe (modelTxt, modelBin);
114
116
// ! [Read and initialize network]
115
117
}
116
- catch (cv::Exception& e) {
118
+ catch (const cv::Exception& e) {
117
119
std::cerr << " Exception: " << e.what () << std::endl;
118
120
// ! [Check that network was read successfully]
119
121
if (net.empty ())
@@ -169,7 +171,7 @@ int main(int argc, char **argv)
169
171
// ! [Gather output]
170
172
171
173
// ! [Print results]
172
- std::vector<String> classNames = readClassNames ();
174
+ std::vector<String> classNames = readClassNames (classNameFile. c_str () );
173
175
std::cout << " Best class: #" << classId << " '" << classNames.at (classId) << " '" << std::endl;
174
176
std::cout << " Probability: " << classProb * 100 << " %" << std::endl;
175
177
// ! [Print results]
0 commit comments