DevYK 3 年 前
コミット
bfa771ea2f
2 ファイル変更17 行追加17 行削除
  1. 12 12
      src/opencv/image_fingerprint.cpp
  2. 5 5
      src/utils/video_similarity.cpp

+ 12 - 12
src/opencv/image_fingerprint.cpp

@@ -12,7 +12,7 @@ int avframeToCvmat(cv::Mat &image, const AVFrame *frame) {
     int cvLinesizes[1];
     cvLinesizes[0] = image.step1();
     int scale_width =8,scale_height = 8;
-    printf("cvmatToAvframe width=%d height=%d linesize[0]=%d  linesize[1]=%d  linesize[2]=%d \n",width,height,frame->linesize[0],frame->linesize[1],frame->linesize[2]);
+//    printf("cvmatToAvframe width=%d height=%d linesize[0]=%d  linesize[1]=%d  linesize[2]=%d \n",width,height,frame->linesize[0],frame->linesize[1],frame->linesize[2]);
     SwsContext *conversion = sws_getContext(width, height, (AVPixelFormat) frame->format, scale_width, scale_height,
                                             AVPixelFormat::AV_PIX_FMT_BGR24, SWS_FAST_BILINEAR, NULL, NULL, NULL);
     if (conversion) {
@@ -73,42 +73,42 @@ AVFrame *cvmatToAvframe(cv::Mat *image, AVFrame *frame) {
 
 int fingerprintFromFFAVFrame(FILE *file, AVFrame *frame, char buf[64]) {
     if (file) fprintf(file, "fingerprintFromFFAVFrame\n");
-    printf("fingerprintFromFFAVFrame\n");
+//    printf("fingerprintFromFFAVFrame\n");
     if (!frame || frame->width <= 0 || frame->height <= 0)return NULL;
 
     int width = frame->width;
     int height = frame->height;
     int scale_width = 8, scale_height = 8;
-    printf("fingerprintFromFFAVFrame -1\n");
+//    printf("fingerprintFromFFAVFrame -1\n");
     cv::Mat img(scale_height, scale_width, CV_8UC3);
-    printf("fingerprintFromFFAVFrame -2\n");
+//    printf("fingerprintFromFFAVFrame -2\n");
     int ret = avframeToCvmat(img, frame);
     if (ret < 0) {
         printf("sws_getContext init error .\n");
         return -1;
     }
-    printf("fingerprintFromFFAVFrame -6\n");
+//    printf("fingerprintFromFFAVFrame -6\n");
     if (img.empty()) {
         printf("image is empty.");
         return NULL;
     }
     if (file) fprintf(file, "fingerprintFromFFAVFrame 2\n");
-    printf("fingerprintFromFFAVFrame 2\n");
+//    printf("fingerprintFromFFAVFrame 2\n");
 //    std::string str = frame->pts + "";
 //    imshow(str, img);
 
     cv::Mat gray, res;
     if (file) fprintf(file, "fingerprintFromFFAVFrame 3\n");
-    printf("fingerprintFromFFAVFrame 3\n");
+//    printf("fingerprintFromFFAVFrame 3\n");
     //缩放成8x8大小灰度图 todo 会导致 crash 已使用 ffmpeg scale
 //    resize(img, res, Size(scale_width, scale_height));
 //    img.release();
     if (file) fprintf(file, "fingerprintFromFFAVFrame 4\n");
-    printf("fingerprintFromFFAVFrame 4\n");
+//    printf("fingerprintFromFFAVFrame 4\n");
     cvtColor(img, gray, COLOR_BGR2GRAY);
     img.release();
     if (file) fprintf(file, "fingerprintFromFFAVFrame 5\n");
-    printf("fingerprintFromFFAVFrame 5\n");
+//    printf("fingerprintFromFFAVFrame 5\n");
     //获取灰度平均值
     cv::Mat mat_mean, mat_stddev;
     meanStdDev(gray, mat_mean, mat_stddev);//求灰度图像的均值、均方差
@@ -120,7 +120,7 @@ int fingerprintFromFFAVFrame(FILE *file, AVFrame *frame, char buf[64]) {
         return -1;
     };
     if (file) fprintf(file, "fingerprintFromFFAVFrame 6\n");
-    printf("fingerprintFromFFAVFrame 6\n");
+//    printf("fingerprintFromFFAVFrame 6\n");
     if (gray.cols * gray.rows < scale_height * scale_width)return NULL;
 //    //得到图像指纹值
     for (int i = 0; i < 8; i++) {
@@ -129,9 +129,9 @@ int fingerprintFromFFAVFrame(FILE *file, AVFrame *frame, char buf[64]) {
         }
     }
     if (file) fprintf(file, "fingerprintFromFFAVFrame 7\n");
-    printf("fingerprintFromFFAVFrame 7\n");
+//    printf("fingerprintFromFFAVFrame 7\n");
     gray.release();
-    printf("fingerprintFromFFAVFrame 8\n");
+//    printf("fingerprintFromFFAVFrame 8\n");
     return scale_width * scale_height;
 }
 

+ 5 - 5
src/utils/video_similarity.cpp

@@ -62,7 +62,7 @@ int video_similarity_detection_start(long id, int force_keyframe,
         char image_hash[64] = {0};
         len = fingerprintFromFFAVFrame(ctx->log, video_frame, image_hash);
         if (ctx->log) fprintf(ctx->log, "fingerprintFromFFAVFrame exit \n");
-        printf("fingerprintFromFFAVFrame exit \n");
+//        printf("fingerprintFromFFAVFrame exit \n");
         if (len > 64) {
             LOGE("size=%d \n", len);
         }
@@ -222,11 +222,11 @@ const char *get_video_similarity_list(const char *inputjson) {
             int n = strlen(((VideoSimilarityContext *) id)->video_path); //计算字符串的长度(包括'\0')
             const char *name = GetFileName(((VideoSimilarityContext *) id)->video_path, n); //把字符串及其长度传给函数
             printf("%s\n", name); //name就是那个名称,可以输出
-            char args[512];
+//            char args[512];
 //            sprintf(args, "/Users/devyk/Data/Project/sample/github_code/OpenCVSample/temp/%s.log", name);
-            sprintf(args, "/datalog/ffmpeg_opencv/%s.log", name);
-            ((VideoSimilarityContext *) id)->log = fopen(args, "wb+");
-            printf("args===%s \n", args);
+//            sprintf(args, "/datalog/ffmpeg_opencv/%s.log", name);
+//            ((VideoSimilarityContext *) id)->log = fopen(args, "wb+");
+//            printf("args===%s \n", args);
             if (((VideoSimilarityContext *) id)->log)fprintf(((VideoSimilarityContext *) id)->log, inputjson);
         }
         if (((VideoSimilarityContext *) id)->log)