@@ -54,8 +54,12 @@ void resize_and_crop(cv::Mat *in_frame, cv::Mat *out_frame) {
54
54
55
55
float largest_factor = factor_w > factor_h ? factor_w : factor_h;
56
56
57
- cv::Size resize_size (static_cast <int >(largest_factor * static_cast <float >(in_frame->cols )),
58
- static_cast <int >(largest_factor * static_cast <float >(in_frame->rows )));
57
+ cv::Size resize_size (ceil (largest_factor * static_cast <float >(in_frame->cols )),
58
+ ceil (largest_factor * static_cast <float >(in_frame->rows )));
59
+
60
+ if (use_debug) {
61
+ printf (" resize_size width=%d height=%d\n " , resize_size.width , resize_size.height );
62
+ }
59
63
60
64
cv::Mat resized;
61
65
cv::resize (*in_frame, resized, resize_size);
@@ -86,7 +90,7 @@ int main(int argc, char** argv) {
86
90
printf (" You can find these via `v4l2-ctl --list-devices`.\n " );
87
91
printf (" E.g. for:\n " );
88
92
printf (" C922 Pro Stream Webcam (usb-70090000.xusb-2.1):\n " );
89
- printf (" /dev/video0\n " );
93
+ printf (" /dev/video0\n " );
90
94
printf (" The ID of the webcam is 0\n " );
91
95
exit (1 );
92
96
}
@@ -105,13 +109,21 @@ int main(int argc, char** argv) {
105
109
return 1 ;
106
110
}
107
111
112
+ // print camera properties
113
+ printf (" " );
114
+ printf (" Camera properties:\n " );
115
+ printf (" width: %d\n " , (int )camera.get (cv::CAP_PROP_FRAME_WIDTH));
116
+ printf (" height: %d\n " , (int )camera.get (cv::CAP_PROP_FRAME_HEIGHT));
117
+ printf (" fps: %d\n " , (int )camera.get (cv::CAP_PROP_FPS));
118
+
108
119
if (use_debug) {
109
120
// create a window to display the images from the webcam
110
121
cv::namedWindow (" Webcam" , cv::WINDOW_AUTOSIZE);
111
122
}
112
123
113
124
// this will contain the image from the webcam
114
125
cv::Mat frame;
126
+ run_classifier_init ();
115
127
116
128
// display the frame until you press a key
117
129
while (1 ) {
@@ -187,9 +199,31 @@ int main(int argc, char** argv) {
187
199
printf (" Visual anomaly values: Mean %.3f Max %.3f\n " , result.visual_ad_result .mean_value , result.visual_ad_result .max_value );
188
200
#endif
189
201
202
+ // print the open traces
203
+ ei_printf (" Open traces:\r\n " );
204
+ for (uint32_t i = 0 ; i < result.postprocessed_output .object_tracking_output .open_traces_count ; i++) {
205
+ ei_object_tracking_trace_t trace = result.postprocessed_output .object_tracking_output .open_traces [i];
206
+ ei_printf (" Trace %d: %s [ x: %u, y: %u, width: %u, height: %u, value: %f ]\r\n " ,
207
+ trace.id ,
208
+ trace.label ,
209
+ trace.x ,
210
+ trace.y ,
211
+ trace.width ,
212
+ trace.height ,
213
+ trace.value );
214
+ }
215
+
190
216
// show the image on the window
191
217
if (use_debug) {
192
- cv::imshow (" Webcam" , cropped);
218
+ // draw the bounding boxes of the traces
219
+ for (uint32_t i = 0 ; i < result.postprocessed_output .object_tracking_output .open_traces_count ; i++) {
220
+ ei_object_tracking_trace_t trace = result.postprocessed_output .object_tracking_output .open_traces [i];
221
+ cv::rectangle (cropped, cv::Rect (trace.x , trace.y , trace.width , trace.height ), cv::Scalar (0 , 255 , 0 ), 2 );
222
+ // add the label and ID
223
+ cv::putText (cropped, std::to_string (trace.id ) + " : " + trace.label , cv::Point (trace.x , trace.y - 10 ), cv::FONT_HERSHEY_SIMPLEX, 0.5 , cv::Scalar (0 , 255 , 0 ), 2 );
224
+ }
225
+ cv::imshow (" File" , cropped);
226
+ output_file.write (cropped);
193
227
// wait (10ms) for a key to be pressed
194
228
if (cv::waitKey (10 ) >= 0 )
195
229
break ;
@@ -200,6 +234,7 @@ int main(int argc, char** argv) {
200
234
usleep (sleep_ms * 1000 );
201
235
}
202
236
}
237
+ run_classifier_deinit ();
203
238
return 0 ;
204
239
}
205
240
0 commit comments