AlexeyAB
2018-03-03 fe44d3d0f29e96714de75234e1fd7e40b05b0296
src/image.c
@@ -14,13 +14,14 @@
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/core/version.hpp"
#include "http_stream.h"
#ifndef CV_VERSION_EPOCH
#include "opencv2/videoio/videoio_c.h"
#include "opencv2/imgcodecs/imgcodecs_c.h"
#include "http_stream.h"
#endif
#endif
int windows = 0;
float colors[6][3] = { {1,0,1}, {0,0,1},{0,1,1},{0,1,0},{1,1,0},{1,0,0} };
@@ -187,8 +188,8 @@
    int i;
    for(i = 0; i < num; ++i){
        int class = max_index(probs[i], classes);
        float prob = probs[i][class];
        int class_id = max_index(probs[i], classes);
        float prob = probs[i][class_id];
        if(prob > thresh){
         //// for comparison with OpenCV version of DNN Darknet Yolo v2
@@ -206,8 +207,8 @@
                alphabet = 0;
            }
            printf("%s: %.0f%%\n", names[class], prob*100);
            int offset = class*123457 % classes;
            printf("%s: %.0f%%\n", names[class_id], prob*100);
            int offset = class_id*123457 % classes;
            float red = get_color(2,offset,classes);
            float green = get_color(1,offset,classes);
            float blue = get_color(0,offset,classes);
@@ -232,7 +233,7 @@
            draw_box_width(im, left, top, right, bot, width, red, green, blue);
            if (alphabet) {
                image label = get_label(alphabet, names[class], (im.h*.03)/10);
                image label = get_label(alphabet, names[class_id], (im.h*.03)/10);
                draw_label(im, top + width, left, label, rgb);
            }
        }
@@ -245,8 +246,8 @@
   int i;
   for (i = 0; i < num; ++i) {
      int class = max_index(probs[i], classes);
      float prob = probs[i][class];
      int class_id = max_index(probs[i], classes);
      float prob = probs[i][class_id];
      if (prob > thresh) {
         int width = show_img->height * .012;
@@ -256,8 +257,8 @@
            alphabet = 0;
         }
         printf("%s: %.0f%%\n", names[class], prob * 100);
         int offset = class * 123457 % classes;
         printf("%s: %.0f%%\n", names[class_id], prob * 100);
         int offset = class_id * 123457 % classes;
         float red = get_color(2, offset, classes);
         float green = get_color(1, offset, classes);
         float blue = get_color(0, offset, classes);
@@ -298,14 +299,14 @@
         color.val[2] = blue * 256;
         cvRectangle(show_img, pt1, pt2, color, width, 8, 0);
         //printf("left=%d, right=%d, top=%d, bottom=%d, obj_id=%d, obj=%s \n", left, right, top, bot, class, names[class]);
         //printf("left=%d, right=%d, top=%d, bottom=%d, obj_id=%d, obj=%s \n", left, right, top, bot, class_id, names[class_id]);
         cvRectangle(show_img, pt_text_bg1, pt_text_bg2, color, width, 8, 0);
         cvRectangle(show_img, pt_text_bg1, pt_text_bg2, color, CV_FILLED, 8, 0);   // filled
         CvScalar black_color;
         black_color.val[0] = 0;
         CvFont font;
         cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, font_size, font_size, 0, font_size * 3, 8); 
         cvPutText(show_img, names[class], pt_text, &font, black_color);
         cvPutText(show_img, names[class_id], pt_text, &font, black_color);
      }
   }
}
@@ -527,7 +528,7 @@
}
void show_image_cv_ipl(IplImage *disp, const char *name, const char *out_filename)
void show_image_cv_ipl(IplImage *disp, const char *name)
{
   if (disp == NULL) return;
   char buff[256];
@@ -537,32 +538,7 @@
   //cvMoveWindow(buff, 100*(windows%10) + 200*(windows/10), 100*(windows%10));
   ++windows;
   cvShowImage(buff, disp);
   if(out_filename)
   {
      CvSize size;
      {
         size.width = disp->width, size.height = disp->height;
      }
      static CvVideoWriter* output_video = NULL;    // cv::VideoWriter output_video;
      if (output_video == NULL)
      {
         //const char* output_name = "test_dnn_out.avi";
         //output_video = cvCreateVideoWriter(out_filename, CV_FOURCC('H', '2', '6', '4'), 25, size, 1);
         output_video = cvCreateVideoWriter(out_filename, CV_FOURCC('D', 'I', 'V', 'X'), 25, size, 1);
         //output_video = cvCreateVideoWriter(out_filename, CV_FOURCC('M', 'J', 'P', 'G'), 25, size, 1);
         //output_video = cvCreateVideoWriter(out_filename, CV_FOURCC('M', 'P', '4', 'V'), 25, size, 1);
         //output_video = cvCreateVideoWriter(out_filename, CV_FOURCC('M', 'P', '4', '2'), 25, size, 1);
         //output_video = cvCreateVideoWriter(out_filename, CV_FOURCC('X', 'V', 'I', 'D'), 25, size, 1);
         //output_video = cvCreateVideoWriter(out_filename, CV_FOURCC('W', 'M', 'V', '2'), 25, size, 1);
      }
      cvWriteFrame(output_video, disp);   // comment this line to improve FPS !!!
      printf("\n cvWriteFrame \n");
   }
   cvReleaseImage(&disp);
   //cvReleaseImage(&disp);
}
#endif