|
@@ -18,7 +18,7 @@ typedef struct VsimBean {
|
|
|
pthread_t id;
|
|
|
} VsimBean;
|
|
|
|
|
|
-static void run(const char * filepath,std::vector<VideoSimilarityModel *> *list){
|
|
|
+static void run(const char *filepath, std::vector<VideoSimilarityModel *> *list) {
|
|
|
long id = video_similarity_detection_init(filepath);
|
|
|
if (id > 0) {
|
|
|
int ret = video_similarity_detection_start(id, 0, AUDIO,
|
|
@@ -32,11 +32,30 @@ static void run(const char * filepath,std::vector<VideoSimilarityModel *> *list)
|
|
|
|
|
|
static void *run_thread(void *p) {
|
|
|
auto *vsimBean = (VsimBean *) p;
|
|
|
- run(vsimBean->filepath,&vsimBean->lists);
|
|
|
+ run(vsimBean->filepath, &vsimBean->lists);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
+static int *list_sim_compare(std::vector<ImageHashModel *> a, std::vector<ImageHashModel *> b) {
|
|
|
+ int minFrames = MIN(a.size(), b.size());
|
|
|
+ int maxFrames = MAX(a.size(), b.size());
|
|
|
+ int sim_frame_count = 0;
|
|
|
+ int arr[2];
|
|
|
+ //比较帧指纹
|
|
|
+ for (int k = 0; k < minFrames; ++k) {
|
|
|
+ float v_sim = fingerprint_compare(a[k]->image_hash, b[k]->image_hash,
|
|
|
+ minFrames);
|
|
|
+ if (v_sim > 0.90) {
|
|
|
+ sim_frame_count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ arr[0] = sim_frame_count;
|
|
|
+ arr[1] = maxFrames;
|
|
|
+ return arr;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 1、判断比对文件的 MD5 是否相等
|
|
|
* 1.1、如果相等,
|
|
@@ -52,17 +71,17 @@ int main(int argc, char *argv[]) {
|
|
|
const char *input_json = "{\n"
|
|
|
" \"videoPath\": \"/Users/devyk/Data/Project/sample/github_code/OpenCVSample/temp/19581045gIiFKepxbbplF3XtsG\",\n"
|
|
|
" \"clips\": [\n"
|
|
|
-// " {\n"
|
|
|
-// " \"startTimeMs\": 0,\n"
|
|
|
-// " \"endTimeMs\": 5000\n"
|
|
|
-// " },\n"
|
|
|
" {\n"
|
|
|
" \"startTimeMs\": 0,\n"
|
|
|
- " \"endTimeMs\": 50\n"
|
|
|
+ " \"endTimeMs\": 1000\n"
|
|
|
+ " },\n"
|
|
|
+ " {\n"
|
|
|
+ " \"startTimeMs\": 2000,\n"
|
|
|
+ " \"endTimeMs\": 3000\n"
|
|
|
" },\n"
|
|
|
" {\n"
|
|
|
- " \"startTimeMs\": 600000,\n"
|
|
|
- " \"endTimeMs\": 610000\n"
|
|
|
+ " \"startTimeMs\": 5000,\n"
|
|
|
+ " \"endTimeMs\": 5500\n"
|
|
|
" }\n"
|
|
|
" ]\n"
|
|
|
"}";
|
|
@@ -83,75 +102,148 @@ int main(int argc, char *argv[]) {
|
|
|
// " ]\n"
|
|
|
// "}";
|
|
|
|
|
|
- auto vs = json2VideoSimilarity(input_json);
|
|
|
+// auto vs = json2VideoSimilarity(input_json);
|
|
|
// auto json = videoSimilarity2json(vs);
|
|
|
|
|
|
int32_t size = 7;
|
|
|
const char *filepath[size];
|
|
|
//票圈视频iOS客户端上传
|
|
|
- filepath[0] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220304/20820121YCuumFJkPsqfRo51So";
|
|
|
+ filepath[0] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220309/17025689Igao51Q0IMBYw8aNKH";
|
|
|
//ios 原生上传
|
|
|
- filepath[1] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220304/20820121sxPL3akcURUIHquge3";
|
|
|
+ filepath[1] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220309/17025689VvI5KURrrxzlZ0Kcdv";
|
|
|
//iOS h5上传
|
|
|
- filepath[2] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220304/20820121rm4gHAdXW1IBr1ASEM";
|
|
|
+ filepath[2] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220309/17025689iBy9WFswYdBNblY9au";
|
|
|
//票圈视频安卓客户端上传
|
|
|
- filepath[3] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220304/200908721BH3GFTuCyThA6LMBY";
|
|
|
+ filepath[3] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220309/17677590exDXG6q75ELejK7aMY";
|
|
|
//安卓h5上传
|
|
|
- filepath[4] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220304/20090872465XAee2WXc6Pjz55z";
|
|
|
+ filepath[4] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220309/176775906GoWtUCYoVZYDbO1XX";
|
|
|
//安卓原生上传
|
|
|
- filepath[5] = "http://rescdn.yishihui.com/longvideo/video/vpc/20220304/20090872DaWq15NTiSgmJvMNwC";
|
|
|
+ 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";
|
|
|
http://rescdn.yishihui.com/longvideo/video/vpc/20220304/17938576TxEh0UJXpzcoYRJuHu
|
|
|
//本地 local 上传的视频
|
|
|
- filepath[6] = "/Users/devyk/Downloads/share_18b774aab823c23d8072d7c45f8b9636.MP4";
|
|
|
+ filepath[6] = "/Users/devyk/Data/Project/sample/github_code/OpenCVSample/temp/19581045gIiFKepxbbplF3XtsG.mp4";
|
|
|
+
|
|
|
+// run(vs->videoPath,&vs->clips);
|
|
|
|
|
|
+// const char * ret = videoSimilarity2json(vs);
|
|
|
|
|
|
- run(vs->videoPath,&vs->clips);
|
|
|
+// const char *local_url = "/Users/devyk/Data/Project/sample/github_code/OpenCVSample/temp/19581045gIiFKepxbbplF3XtsG.mp4";
|
|
|
+// std::vector<VideoSimilarityModel *> local_list;
|
|
|
+// run(local_url, &local_list);
|
|
|
|
|
|
- const char * ret = videoSimilarity2json(vs);
|
|
|
- LOGE("ret =%s \n",ret);
|
|
|
- free((void*)ret);
|
|
|
- return 1;
|
|
|
+ std::vector<VideoSimilarityModel *> lists[size];
|
|
|
+ int split_count = 10;
|
|
|
+// int total = 3960000;
|
|
|
+ int ii = 1000 * 60*6;
|
|
|
|
|
|
- VsimBean vsimBean[size];
|
|
|
+ int start = ii;
|
|
|
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]);
|
|
|
+ auto start_time = getCurrentTimeMills();
|
|
|
+ start = ii;
|
|
|
+ for (int j = 0; j < split_count; ++j) {
|
|
|
+ if (j == 0 || j == split_count-1) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ auto *item = new VideoSimilarityModel();
|
|
|
+ item->startTimeMs = start;
|
|
|
+ item->endTimeMs = item->startTimeMs + 1000;
|
|
|
+ lists[i].push_back(item);
|
|
|
+ start+=ii;
|
|
|
+ }
|
|
|
+ LOGE(">>>filepath=%s \n", filepath[i]);
|
|
|
+ run(filepath[i], &lists[i]);
|
|
|
+ LOGE("<<<filepath=%s cost time=%lld \n", filepath[i], getCurrentTimeMills() - start_time);
|
|
|
}
|
|
|
- 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());
|
|
|
+
|
|
|
+ //本地 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) {
|
|
|
+ for (int g = 0; g < lists[j].size(); ++g) {
|
|
|
+ int *cur_sim = list_sim_compare(local[g]->hashs, lists[j][g]->hashs);
|
|
|
+ int a = cur_sim[0];
|
|
|
+ int b = cur_sim[1];
|
|
|
+ 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;
|
|
|
+ for (int j = 0; j < 8; ++j) {
|
|
|
+ a_t += test_vis[i][j];
|
|
|
+ b_t += test_vis_total[i][j];
|
|
|
+ }
|
|
|
+ LOGE("%s %s 相似度 = %f \n", filepath[6],filepath[i],a_t*1.0/b_t*1.0);
|
|
|
}
|
|
|
+ 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);
|
|
|
+// 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++;
|
|
|
+// }
|
|
|
// }
|
|
|
- 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("path1=%s path2=%s 相似度=%f \n", a.filepath, b.filepath,
|
|
|
+// (float) sim_frame_count / (float) maxFrames);
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
LOGE("end \n");
|
|
|
return 0;
|