Minor demo fix

pull/2383/head
AlexeyAB 6 years ago
parent f154d2070a
commit 7dff7365cb
  1. 89
      src/demo.c

@ -31,8 +31,9 @@ static char **demo_names;
static image **demo_alphabet;
static int demo_classes;
static float **probs;
static box *boxes;
static int nboxes = 0;
static detection *dets = NULL;
static network net;
static image in_s ;
static image det_s;
@ -50,7 +51,6 @@ static image images[FRAMES];
static IplImage* ipl_images[FRAMES];
static float *avg;
void draw_detections_cv(IplImage* show_img, int num, float thresh, box *boxes, float **probs, char **names, image **alphabet, int classes);
void draw_detections_cv_v3(IplImage* show_img, detection *dets, int num, float thresh, char **names, image **alphabet, int classes, int ext_output);
void show_image_cv_ipl(IplImage *disp, const char *name);
void save_cv_png(IplImage *img, const char *name);
@ -86,8 +86,6 @@ void *fetch_in_thread(void *ptr)
void *detect_in_thread(void *ptr)
{
float nms = .45; // 0.4F
layer l = net.layers[net.n-1];
float *X = det_s.data;
float *prediction = network_predict(net, X);
@ -98,33 +96,14 @@ void *detect_in_thread(void *ptr)
free_image(det_s);
int nboxes = 0;
detection *dets = NULL;
if (letter_box)
dets = get_network_boxes(&net, in_img->width, in_img->height, demo_thresh, demo_thresh, 0, 1, &nboxes, 1); // letter box
else
dets = get_network_boxes(&net, det_s.w, det_s.h, demo_thresh, demo_thresh, 0, 1, &nboxes, 0); // resized
//if (nms) do_nms_obj(dets, nboxes, l.classes, nms); // bad results
if (nms) do_nms_sort(dets, nboxes, l.classes, nms);
printf("\033[2J");
printf("\033[1;1H");
printf("\nFPS:%.1f\n",fps);
printf("Objects:\n\n");
ipl_images[demo_index] = det_img;
det_img = ipl_images[(demo_index + FRAMES / 2 + 1) % FRAMES];
demo_index = (demo_index + 1)%FRAMES;
++frame_id;
if (demo_json_port > 0) {
int timeout = 200;
send_json(dets, nboxes, l.classes, demo_names, frame_id, demo_json_port, timeout);
}
demo_index = (demo_index + 1) % FRAMES;
draw_detections_cv_v3(det_img, dets, nboxes, demo_thresh, demo_names, demo_alphabet, demo_classes, demo_ext_output);
free_detections(dets, nboxes);
if (letter_box)
dets = get_network_boxes(&net, in_img->width, in_img->height, demo_thresh, demo_thresh, 0, 1, &nboxes, 1); // letter box
else
dets = get_network_boxes(&net, net.w, net.h, demo_thresh, demo_thresh, 0, 1, &nboxes, 0); // resized
return 0;
}
@ -163,20 +142,12 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
if(filename){
printf("video file: %s\n", filename);
//#ifdef CV_VERSION_EPOCH // OpenCV 2.x
// cap = cvCaptureFromFile(filename);
//#else // OpenCV 3.x
cpp_video_capture = 1;
cap = get_capture_video_stream(filename);
//#endif
}else{
printf("Webcam index: %d\n", cam_index);
//#ifdef CV_VERSION_EPOCH // OpenCV 2.x
// cap = cvCaptureFromCAM(cam_index);
//#else // OpenCV 3.x
cpp_video_capture = 1;
cap = get_capture_webcam(cam_index);
//#endif
}
if (!cap) {
@ -193,10 +164,6 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
for(j = 0; j < FRAMES; ++j) predictions[j] = (float *) calloc(l.outputs, sizeof(float));
for(j = 0; j < FRAMES; ++j) images[j] = make_image(1,1,3);
boxes = (box *)calloc(l.w*l.h*l.n, sizeof(box));
probs = (float **)calloc(l.w*l.h*l.n, sizeof(float *));
for(j = 0; j < l.w*l.h*l.n; ++j) probs[j] = (float *)calloc(l.classes, sizeof(float *));
if (l.classes != demo_classes) {
printf("Parameters don't match: in cfg-file classes=%d, in data-file classes=%d \n", l.classes, demo_classes);
getchar();
@ -254,10 +221,31 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
while(1){
++count;
if(1){
{
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");
float nms = .45; // 0.4F
int local_nboxes = nboxes;
detection *local_dets = dets;
//if (nms) do_nms_obj(local_dets, local_nboxes, l.classes, nms); // bad results
if (nms) do_nms_sort(local_dets, local_nboxes, l.classes, nms);
printf("\033[2J");
printf("\033[1;1H");
printf("\nFPS:%.1f\n", fps);
printf("Objects:\n\n");
++frame_id;
if (demo_json_port > 0) {
int timeout = 200;
send_json(local_dets, local_nboxes, l.classes, demo_names, frame_id, demo_json_port, timeout);
}
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);
if(!prefix){
if (!dont_show) {
show_image_cv_ipl(show_img, "Demo");
@ -281,7 +269,6 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
// if you run it with param -mjpeg_port 8090 then open URL in your web-browser: http://localhost:8090
if (mjpeg_port > 0 && show_img) {
//int port = 8090;
int port = mjpeg_port;
int timeout = 200;
int jpeg_quality = 30; // 1 - 100
@ -306,18 +293,6 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
}
det_img = in_img;
det_s = in_s;
}else {
fetch_in_thread(0);
det_img = in_img;
det_s = in_s;
detect_in_thread(0);
show_img = det_img;
if (!dont_show) {
show_image_cv_ipl(show_img, "Demo");
cvWaitKey(1);
}
cvReleaseImage(&show_img);
}
--delay;
if(delay < 0){
@ -344,10 +319,6 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
for (j = 0; j < FRAMES; ++j) free(predictions[j]);
for (j = 0; j < FRAMES; ++j) free_image(images[j]);
for (j = 0; j < l.w*l.h*l.n; ++j) free(probs[j]);
free(boxes);
free(probs);
free_ptrs(names, net.layers[net.n - 1].classes);
int i;

Loading…
Cancel
Save