@@ -83,13 +83,29 @@ static std::vector<String> readClassNames(const char *filename = "synset_words.t
83
83
return classNames;
84
84
}
85
85
86
+ const char * params
87
+ = " { help | false | Sample app for loading googlenet model }"
88
+ " { proto | bvlc_googlenet.prototxt | model configuration }"
89
+ " { model | bvlc_googlenet.caffemodel | model weights }"
90
+ " { image | space_shuttle.jpg | path to image file }"
91
+ " { opencl | false | enable OpenCL }"
92
+ ;
93
+
86
94
int main (int argc, char **argv)
87
95
{
88
96
CV_TRACE_FUNCTION ();
89
97
90
- String modelTxt = " bvlc_googlenet.prototxt" ;
91
- String modelBin = " bvlc_googlenet.caffemodel" ;
92
- String imageFile = (argc > 1 ) ? argv[1 ] : " space_shuttle.jpg" ;
98
+ CommandLineParser parser (argc, argv, params);
99
+
100
+ if (parser.get <bool >(" help" ))
101
+ {
102
+ parser.printMessage ();
103
+ return 0 ;
104
+ }
105
+
106
+ String modelTxt = parser.get <string>(" proto" );
107
+ String modelBin = parser.get <string>(" model" );
108
+ String imageFile = parser.get <String>(" image" );
93
109
94
110
Net net;
95
111
try {
@@ -112,6 +128,11 @@ int main(int argc, char **argv)
112
128
// ! [Check that network was read successfully]
113
129
}
114
130
131
+ if (parser.get <bool >(" opencl" ))
132
+ {
133
+ net.setPreferableTarget (DNN_TARGET_OPENCL);
134
+ }
135
+
115
136
// ! [Prepare blob]
116
137
Mat img = imread (imageFile);
117
138
if (img.empty ())
@@ -124,8 +145,9 @@ int main(int argc, char **argv)
124
145
Mat inputBlob = blobFromImage (img, 1 .0f , Size (224 , 224 ),
125
146
Scalar (104 , 117 , 123 ), false ); // Convert Mat to batch of images
126
147
// ! [Prepare blob]
148
+ net.setInput (inputBlob, " data" ); // set the network input
149
+ Mat prob = net.forward (" prob" ); // compute output
127
150
128
- Mat prob;
129
151
cv::TickMeter t;
130
152
for (int i = 0 ; i < 10 ; i++)
131
153
{
0 commit comments