Pārlūkot izejas kodu

视频分段相似识别完成-jni

DevYK 3 gadi atpakaļ
vecāks
revīzija
f0631984e1

+ 56 - 0
README.md

@@ -1,5 +1,6 @@
 ## OpenCV 项目
 
+
 ### [模糊检测原理](https://pyimagesearch.com/2015/09/07/blur-detection-with-opencv/)
 整个算法的原理和拉普拉斯算子本身的定义有关,该算子主要用来测量图像的二阶导数。它强调了包含快速强度变化的图像区域。拉普拉斯算子经常被用来做边缘检测。这里存在着一个假设,即如果一个图像中包含着高方差,那么在图像中会有较大范围的响应,包括边缘和非边缘,这代表着一张正常图像。但是如果该图像的方差很低,那么响应的范围很小,这表明图像中的边缘很小。众所周知的是当图像越模糊时,包含的边缘信息就会越少
 
@@ -121,3 +122,58 @@ PQCVMediaProcessor.blurDetectionFromImagePath(String path);
 
 ```
 
+
+### 获取视频指纹码,用于比较是否相似
+
+#### 环境配置
+1. FFmpeg 安装 >=4.4.1 (建议 4.4.1)
+   ```shell
+
+   yum-config-manager --add-repo=https://negativo17.org/repos/epel-multimedia.repo
+   yum-config-manager --disable epel-multimedia
+   yum install --enablerepo=epel-multimedia ffmpeg ffmpeg-devel
+   
+   ```
+2. OpenCV 安装 (参考上面)
+3. JAVA   安装 (参考上面)
+
+#### api
+
+**inputjson:**
+
+strartTimeMs,endTimeMs 时间建议传递 8 段,每段为 1s,比如视频时长 100min,去掉前面 10%,尾部 10%,然后需要中间的 80% 做检查,每隔 10 分钟截取 1s 即可。
+
+```json
+
+{
+   "videoPath": "\"xxx.mp4\"",
+   "clips": [
+      {
+         "strartTimeMs": 10*60*1000,//10 分钟
+         "endTimeMs": 10*60*1000 + 1000,//10分1秒
+         "hashs": [ //结果返回 start -> end 每张图片 标识用于比较
+            {
+               "imageHash": "\"000010000101010010101010\"",
+               "hashSize": 64,
+               "pts": 0
+            },
+            {
+               "imageHash": "\"000010000101010010101010\"",
+               "hashSize": 64,
+               "pts": 40
+            }
+         ]
+      }
+   ]
+}
+
+```
+
+```shell
+PQCVMediaProcessor.java
+static String getVideoSimilarityLists(String inputjson)
+
+
+```
+
+

+ 2 - 0
jni/ImageBlurDetection.cpp

@@ -18,6 +18,8 @@ static jstring Java_JNI_OpenCV_GetVideoSimilarityLists(JNIEnv *env, jobject obj,
     env->ReleaseStringUTFChars(filepath, image_path);
     if (ret_json) {
         jstring str = env->NewStringUTF(ret_json);
+        free((void *) ret_json);
+        ret_json = NULL;
         return str;
     }
     return NULL;

BIN
output/jar/libpq-cv-media-22.2.24.jar


BIN
output/jar/libpq-cv-media.jar


+ 3 - 65
src/video_similarity_comparison.cpp

@@ -120,8 +120,8 @@ int main(int argc, char *argv[]) {
     //安卓原生上传
     filepath[5] = "";
     //PC 上传
-    filepath[5] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220309/17025689nSyGzifJFr4Apl0zc8";
-//    filepath[5] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220304/20090872TkYCoGR785GKZPPM7K";
+//    filepath[5] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220309/17025689nSyGzifJFr4Apl0zc8";
+    filepath[5] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220310/701939000F0qpyCLetflI3COz";
     http://rescdn.yishihui.com/longvideo/video/vpc/20220304/17938576TxEh0UJXpzcoYRJuHu
     //本地 local 上传的视频
     filepath[6] = "/Users/devyk/Data/Project/sample/github_code/OpenCVSample/temp/19581045gIiFKepxbbplF3XtsG.mp4";
@@ -160,16 +160,6 @@ int main(int argc, char *argv[]) {
 
     //本地 local
     std::vector<VideoSimilarityModel *> local = lists[size - 1];
-    int *total_sim[size - 1];
-
-    //本地检查的结果
-//    for (int i = 0; i < local.size(); ++i) {
-    //第 i 本地层的 hashs
-//        std::vector<ImageHashModel *> local_hashs = local[i]->hashs;
-
-    //对比的视频 size
-
-
     int test_vis[6][10] = {0};
     int test_vis_total[6][10] = {0};
     for (int j = 0; j < size - 1; ++j) {
@@ -180,15 +170,8 @@ int main(int argc, char *argv[]) {
             test_vis[j][g] = a;
             test_vis_total[j][g] = b;
         }
-
-//        int *cur_sim = list_sim_compare(local[0]->hashs, lists[j][0]->hashs);
-//        int a = cur_sim[0];
-//        int b  = cur_sim[1];
-//        test_vis[j][0] = a;
-//        test_vis_total[j][0] = b;
-
     }
-//    LOGE("相似度 = %f \n", sim_v * 1.0 / total_v * 1.0);
+
 
     for (int i = 0; i <size-1; ++i) {
         int a_t = 0,b_t = 0;
@@ -200,51 +183,6 @@ int main(int argc, char *argv[]) {
     }
     printf("");
 
-//    const char *ret = get_video_similarity_list(input_json);
-//    printf("ret =%s \n", ret);
-//    free((void *) ret);
-//    return 1;
-
-//    VsimBean vsimBean[size];
-//    for (int i = 0; i < size; ++i) {
-//        vsimBean[i].filepath = strdup(filepath[i]);
-////        vsimBean[i].lists = vs->clips[i];
-//        pthread_create(&vsimBean[i].id, 0, run_thread, &vsimBean[i]);
-//    }
-//    for (int i = 0; i < size; ++i) {
-//        pthread_join(vsimBean[i].id, 0);
-//        LOGE("################# path=%s size=%d \n", vsimBean[i].filepath, vsimBean[i].lists.size());
-//    }
-
-    //开始比较
-//    for (int i = 0; i < size; ++i) {
-//    for (int i = 0; i < 1; ++i) {
-//        auto a = vsimBean[6];
-//        for (int j = i; j < size - 1; ++j) {
-//            auto b = vsimBean[j];
-//            //比较 md5
-////            if (md5_is_exactly_the_same(a.image_md5, b.image_md5) == 0) {
-////                LOGE("path1=%s path2=%s MD5 完全相似\n", a.filepath, b.filepath);
-////                continue;
-////            } else {
-////                LOGE("path1=%s path2=%s MD5 完全不相似\n", a.filepath, b.filepath);
-////            }
-//            int minFrames = MIN(a.lists.size(), b.lists.size());
-//            int maxFrames = MAX(a.lists.size(), b.lists.size());
-//            int sim_frame_count = 0;
-//            //比较帧指纹
-//            for (int k = 0; k < minFrames; ++k) {
-//                float v_sim = fingerprint_compare(a.lists[k]->image_hash, b.lists[k]->image_hash,
-//                                                  MIN(a.lists[k]->img_len, b.lists[k]->img_len));
-//                if (v_sim > 0.90) {
-//                    sim_frame_count++;
-//                }
-//            }
-//            LOGE("path1=%s path2=%s 相似度=%f   \n", a.filepath, b.filepath,
-//                 (float) sim_frame_count / (float) maxFrames);
-//        }
-//    }
-
     LOGE("end \n");
     return 0;
 }