AlexeyAB / darknet

YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
http://pjreddie.com/darknet/
Other
21.57k stars 7.95k forks source link

some problem about your code in demo.c #4571

Open yzpfyang opened 4 years ago

yzpfyang commented 4 years ago

hi, AlexeyAB. I have some problem about those code in demo.c:

while(1){ ++count; { 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 = 400000;
            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);

        printf("\nFPS:%.1f\n", fps);

        if(!prefix){
            if (!dont_show) {
                show_image_mat(show_img, "Demo");
                int c = wait_key_cv(1);
                if (c == 10) {
                    if (frame_skip == 0) frame_skip = 60;
                    else if (frame_skip == 4) frame_skip = 0;
                    else if (frame_skip == 60) frame_skip = 4;
                    else frame_skip = 0;
                }
                else if (c == 27 || c == 1048603) // ESC - exit (OpenCV 2.x / 3.x)
                {
                    flag_exit = 1;
                }
            }
        }else{
            char buff[256];
            //sprintf(buff, "%s_%08d.jpg", prefix, count);
            sprintf(buff, "res/%s_%d.jpg", prefix, count);
            if(show_img) save_cv_jpg(show_img, buff);
        }

        // 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 = mjpeg_port;
            int timeout = 400000;
            int jpeg_quality = 40;    // 1 - 100
            send_mjpeg(show_img, port, timeout, jpeg_quality);
        }

        // save video file
        if (output_video_writer && show_img) {
            write_frame_cv(output_video_writer, show_img);
            printf("\n cvWriteFrame \n");
        }

        release_mat(&show_img);

        pthread_join(fetch_thread, 0);
        pthread_join(detect_thread, 0);

        if (flag_exit == 1) break;

        if(delay == 0){
            show_img = det_img;
        }
        det_img = in_img;
        det_s = in_s;
    }
    --delay;
    if(delay < 0){
        delay = frame_skip;

        //double after = get_wall_time();
        //float curr = 1./(after - before);
        double after = get_time_point();    // more accurate time measurements
        float curr = 1000000. / (after - before);
        fps = curr;
        before = after;
    }
}

when i use command line " ./darknet detector demo ..... -prefix 1" to save result pictures. i find no first frame in my res folder . then i search your code ,and a little confused:

  1. first frame is detected and dont show?
  2. do detection on the second frame and show the box on the first?
AlexeyAB commented 4 years ago

Set 1 there https://github.com/AlexeyAB/darknet/blob/master/src/demo.c#L41