Browse Source

crash test 4

DevYK 3 years ago
parent
commit
593847f613
3 changed files with 16 additions and 26 deletions
  1. 9 13
      src/opencv/image_fingerprint.cpp
  2. 1 1
      src/opencv/image_fingerprint.h
  3. 6 12
      src/utils/video_similarity.cpp

+ 9 - 13
src/opencv/image_fingerprint.cpp

@@ -37,19 +37,17 @@ AVFrame *cvmatToAvframe(cv::Mat *image, AVFrame *frame) {
     return frame;
 }
 
-const char *fingerprintFromFFAVFrame(FILE *file, AVFrame *frame, int *len) {
+int fingerprintFromFFAVFrame(FILE *file, AVFrame *frame,char buf[64]) {
     if (file) fprintf(file, "fingerprintFromFFAVFrame\n");
     if (!frame)return NULL;
 
-    if (1) {
-        static char buf[64];
-        memset((void *)buf, 0,sizeof(char) * 8 * 8);
-        for (int i = 0; i <64 ; ++i) {
-            buf[i] = 1;
-        }
-        *len = 64;
-        return buf;
-    }
+//    if (1) {
+//        memset((void *)buf, 0,sizeof(char) * 8 * 8);
+//        for (int i = 0; i <64 ; ++i) {
+//            buf[i] = 1;
+//        }
+//        return 64;
+//    }
 
 //    auto img = avframeToCvmat(frame);
     int width = frame->width;
@@ -79,7 +77,6 @@ const char *fingerprintFromFFAVFrame(FILE *file, AVFrame *frame, int *len) {
     //获取灰度平均值
     double mn = mean(gray)[0];
     if (file) fprintf(file, "fingerprintFromFFAVFrame 6\n");
-    static char buf[64];
     if (file) fprintf(file, "fingerprintFromFFAVFrame 7\n");
     if (gray.cols * gray.rows < scale_height * scale_width)return NULL;
 //    //得到图像指纹值
@@ -89,9 +86,8 @@ const char *fingerprintFromFFAVFrame(FILE *file, AVFrame *frame, int *len) {
         }
     }
     if (file) fprintf(file, "fingerprintFromFFAVFrame 8\n");
-    *len = scale_width * scale_height;
     if (file) fprintf(file, "fingerprintFromFFAVFrame 9\n");
-    return buf;
+    return scale_width * scale_height;
 }
 
 float fingerprint_compare(const char *arr, const char *arr2, int len) {

+ 1 - 1
src/opencv/image_fingerprint.h

@@ -23,7 +23,7 @@ cv::Mat avframeToCvmat(const AVFrame * frame);
 AVFrame* cvmatToAvframe(cv::Mat* image, AVFrame * frame);
 
 
-const char *fingerprintFromFFAVFrame(FILE *file,AVFrame *frame, int *pInt);
+int fingerprintFromFFAVFrame(FILE *file,AVFrame *frame,char image_hash[64]);
 
 /**
  * 指纹相识度

+ 6 - 12
src/utils/video_similarity.cpp

@@ -130,14 +130,8 @@ int video_similarity_detection_start(long id, int force_keyframe,
 
         int len = 0;
         if (ctx->log) fprintf(ctx->log, "fingerprintFromFFAVFrame 1\n");
-        const char *image_hash = fingerprintFromFFAVFrame(ctx->log, video_frame, &len);
-//        char image_hash[64] = {0};
-//        if (1) {
-//            for (int i = 0; i < 64; ++i) {
-//                image_hash[i] = 1;
-//            }
-//            len = 64;
-//        }
+        char image_hash[64] = {0};
+        len = fingerprintFromFFAVFrame(ctx->log, video_frame, image_hash);
         if (ctx->log) fprintf(ctx->log, "fingerprintFromFFAVFrame exit \n");
         if (len > 64) {
             LOGE("size=%d \n", len);
@@ -147,8 +141,8 @@ int video_similarity_detection_start(long id, int force_keyframe,
         model->img_len = len;
 
         if (len > 0) {
-            model->image_hash = static_cast<char *>(malloc(sizeof(char) * len+1));
-            memset((void *) model->image_hash, '\0', sizeof(char) * len+1);
+            model->image_hash = static_cast<char *>(malloc(sizeof(char) * len + 1));
+            memset((void *) model->image_hash, '\0', sizeof(char) * len + 1);
             string append_array;
             for (int i = 0; i < len; ++i) {
                 char c = image_hash[i];
@@ -159,7 +153,7 @@ int video_similarity_detection_start(long id, int force_keyframe,
                 }
             }
             append_array.append("\0");
-            memcpy((char*)model->image_hash, append_array.c_str(), strlen(append_array.c_str()));
+            memcpy((char *) model->image_hash, append_array.c_str(), strlen(append_array.c_str()));
         }
         if (video_frame->pts >= endTimeMs && (*lists).size() > 1 && index + 1 < (*lists).size()) {
             index++;
@@ -254,7 +248,7 @@ const char *videoSimilarity2json(VideoSimilarity *videoSimilarity) {
 //                    }
 //                }
                 va["imageHash"] = item2->image_hash;
-                printf("item2->image_hash address=%p \n",&item2->image_hash);
+//                printf("item2->image_hash address=%p \n",&item2->image_hash);
                 free((void *) item2->image_hash);
                 item2->image_hash = NULL;
             }