|
|
@ -80,8 +80,6 @@ void *detect_in_thread(void *ptr) |
|
|
|
mean_arrays(predictions, NFRAMES, l.outputs, avg); |
|
|
|
mean_arrays(predictions, NFRAMES, l.outputs, avg); |
|
|
|
l.output = avg; |
|
|
|
l.output = avg; |
|
|
|
|
|
|
|
|
|
|
|
free_image(det_s); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cv_images[demo_index] = det_img; |
|
|
|
cv_images[demo_index] = det_img; |
|
|
|
det_img = cv_images[(demo_index + NFRAMES / 2 + 1) % NFRAMES]; |
|
|
|
det_img = cv_images[(demo_index + NFRAMES / 2 + 1) % NFRAMES]; |
|
|
|
demo_index = (demo_index + 1) % NFRAMES; |
|
|
|
demo_index = (demo_index + 1) % NFRAMES; |
|
|
@ -104,7 +102,8 @@ double get_wall_time() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int cam_index, const char *filename, char **names, int classes, |
|
|
|
void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int cam_index, const char *filename, char **names, int classes, |
|
|
|
int frame_skip, char *prefix, char *out_filename, int mjpeg_port, int json_port, int dont_show, int ext_output, int letter_box_in, int time_limit_sec, char *http_post_host) |
|
|
|
int frame_skip, char *prefix, char *out_filename, int mjpeg_port, int json_port, int dont_show, int ext_output, int letter_box_in, int time_limit_sec, char *http_post_host, |
|
|
|
|
|
|
|
int benchmark, int benchmark_layers) |
|
|
|
{ |
|
|
|
{ |
|
|
|
letter_box = letter_box_in; |
|
|
|
letter_box = letter_box_in; |
|
|
|
in_img = det_img = show_img = NULL; |
|
|
|
in_img = det_img = show_img = NULL; |
|
|
@ -122,6 +121,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int |
|
|
|
if(weightfile){ |
|
|
|
if(weightfile){ |
|
|
|
load_weights(&net, weightfile); |
|
|
|
load_weights(&net, weightfile); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
net.benchmark_layers = benchmark_layers; |
|
|
|
fuse_conv_batchnorm(net); |
|
|
|
fuse_conv_batchnorm(net); |
|
|
|
calculate_binary_weights(net); |
|
|
|
calculate_binary_weights(net); |
|
|
|
srand(2222222); |
|
|
|
srand(2222222); |
|
|
@ -202,7 +202,10 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int |
|
|
|
|
|
|
|
|
|
|
|
int send_http_post_once = 0; |
|
|
|
int send_http_post_once = 0; |
|
|
|
const double start_time_lim = get_time_point(); |
|
|
|
const double start_time_lim = get_time_point(); |
|
|
|
double before = get_wall_time(); |
|
|
|
double before = get_time_point(); |
|
|
|
|
|
|
|
double start_time = get_time_point(); |
|
|
|
|
|
|
|
float avg_fps = 0; |
|
|
|
|
|
|
|
int frame_counter = 0; |
|
|
|
|
|
|
|
|
|
|
|
while(1){ |
|
|
|
while(1){ |
|
|
|
++count; |
|
|
|
++count; |
|
|
@ -211,7 +214,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int |
|
|
|
int local_nboxes = nboxes; |
|
|
|
int local_nboxes = nboxes; |
|
|
|
detection *local_dets = dets; |
|
|
|
detection *local_dets = dets; |
|
|
|
|
|
|
|
|
|
|
|
if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed"); |
|
|
|
if (!benchmark) if (pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed"); |
|
|
|
if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed"); |
|
|
|
if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed"); |
|
|
|
|
|
|
|
|
|
|
|
//if (nms) do_nms_obj(local_dets, local_nboxes, l.classes, nms); // bad results
|
|
|
|
//if (nms) do_nms_obj(local_dets, local_nboxes, l.classes, nms); // bad results
|
|
|
@ -242,10 +245,10 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
draw_detections_cv_v3(show_img, local_dets, local_nboxes, demo_thresh, demo_names, demo_alphabet, demo_classes, demo_ext_output); |
|
|
|
if (!benchmark) draw_detections_cv_v3(show_img, local_dets, local_nboxes, demo_thresh, demo_names, demo_alphabet, demo_classes, demo_ext_output); |
|
|
|
free_detections(local_dets, local_nboxes); |
|
|
|
free_detections(local_dets, local_nboxes); |
|
|
|
|
|
|
|
|
|
|
|
printf("\nFPS:%.1f\n", fps); |
|
|
|
printf("\nFPS:%.1f \t AVG_FPS:%.1f\n", fps, avg_fps); |
|
|
|
|
|
|
|
|
|
|
|
if(!prefix){ |
|
|
|
if(!prefix){ |
|
|
|
if (!dont_show) { |
|
|
|
if (!dont_show) { |
|
|
@ -282,9 +285,11 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int |
|
|
|
printf("\n cvWriteFrame \n"); |
|
|
|
printf("\n cvWriteFrame \n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pthread_join(fetch_thread, 0); |
|
|
|
|
|
|
|
pthread_join(detect_thread, 0); |
|
|
|
pthread_join(detect_thread, 0); |
|
|
|
|
|
|
|
if (!benchmark) { |
|
|
|
|
|
|
|
pthread_join(fetch_thread, 0); |
|
|
|
|
|
|
|
free_image(det_s); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (time_limit_sec > 0 && (get_time_point() - start_time_lim)/1000000 > time_limit_sec) { |
|
|
|
if (time_limit_sec > 0 && (get_time_point() - start_time_lim)/1000000 > time_limit_sec) { |
|
|
|
printf(" start_time_lim = %f, get_time_point() = %f, time spent = %f \n", start_time_lim, get_time_point(), get_time_point() - start_time_lim); |
|
|
|
printf(" start_time_lim = %f, get_time_point() = %f, time spent = %f \n", start_time_lim, get_time_point(), get_time_point() - start_time_lim); |
|
|
@ -294,7 +299,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int |
|
|
|
if (flag_exit == 1) break; |
|
|
|
if (flag_exit == 1) break; |
|
|
|
|
|
|
|
|
|
|
|
if(delay == 0){ |
|
|
|
if(delay == 0){ |
|
|
|
release_mat(&show_img); |
|
|
|
if(!benchmark) release_mat(&show_img); |
|
|
|
show_img = det_img; |
|
|
|
show_img = det_img; |
|
|
|
} |
|
|
|
} |
|
|
|
det_img = in_img; |
|
|
|
det_img = in_img; |
|
|
@ -308,8 +313,17 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int |
|
|
|
//float curr = 1./(after - before);
|
|
|
|
//float curr = 1./(after - before);
|
|
|
|
double after = get_time_point(); // more accurate time measurements
|
|
|
|
double after = get_time_point(); // more accurate time measurements
|
|
|
|
float curr = 1000000. / (after - before); |
|
|
|
float curr = 1000000. / (after - before); |
|
|
|
fps = curr; |
|
|
|
fps = fps*0.9 + curr*0.1; |
|
|
|
before = after; |
|
|
|
before = after; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float spent_time = (get_time_point() - start_time) / 1000000; |
|
|
|
|
|
|
|
frame_counter++; |
|
|
|
|
|
|
|
if (spent_time >= 3.0f) { |
|
|
|
|
|
|
|
//printf(" spent_time = %f \n", spent_time);
|
|
|
|
|
|
|
|
avg_fps = frame_counter / spent_time; |
|
|
|
|
|
|
|
frame_counter = 0; |
|
|
|
|
|
|
|
start_time = get_time_point(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
printf("input video stream closed. \n"); |
|
|
|
printf("input video stream closed. \n"); |
|
|
@ -345,7 +359,8 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int |
|
|
|
} |
|
|
|
} |
|
|
|
#else |
|
|
|
#else |
|
|
|
void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int cam_index, const char *filename, char **names, int classes, |
|
|
|
void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int cam_index, const char *filename, char **names, int classes, |
|
|
|
int frame_skip, char *prefix, char *out_filename, int mjpeg_port, int json_port, int dont_show, int ext_output, int letter_box_in, int time_limit_sec, char *http_post_host) |
|
|
|
int frame_skip, char *prefix, char *out_filename, int mjpeg_port, int json_port, int dont_show, int ext_output, int letter_box_in, int time_limit_sec, char *http_post_host, |
|
|
|
|
|
|
|
int benchmark, int benchmark_layers) |
|
|
|
{ |
|
|
|
{ |
|
|
|
fprintf(stderr, "Demo needs OpenCV for webcam images.\n"); |
|
|
|
fprintf(stderr, "Demo needs OpenCV for webcam images.\n"); |
|
|
|
} |
|
|
|
} |
|
|
|