jhj0517 commited on
Commit
aa6793a
·
1 Parent(s): 7f1c59d

Add video compare function

Browse files
Files changed (1) hide show
  1. tests/test_config.py +28 -0
tests/test_config.py CHANGED
@@ -4,6 +4,8 @@ import os
4
  import torch
5
  import functools
6
  import numpy as np
 
 
7
 
8
  from modules.utils.paths import *
9
 
@@ -42,6 +44,32 @@ def are_images_different(image1_path: str, image2_path: str):
42
  return True
43
 
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  @functools.lru_cache
46
  def is_cuda_available():
47
  return torch.cuda.is_available()
 
4
  import torch
5
  import functools
6
  import numpy as np
7
+ import cv2
8
+ from skimage.metrics import structural_similarity as compare_ssim
9
 
10
  from modules.utils.paths import *
11
 
 
44
  return True
45
 
46
 
47
+ def are_videos_different(video1_path: str, video2_path: str):
48
+ cap1 = cv2.VideoCapture(video1_path)
49
+ cap2 = cv2.VideoCapture(video2_path)
50
+
51
+ while True:
52
+ ret1, frame1 = cap1.read()
53
+ ret2, frame2 = cap2.read()
54
+
55
+ if not ret1 or not ret2:
56
+ if ret1 != ret2:
57
+ return True
58
+ break
59
+
60
+ if frame1.shape != frame2.shape:
61
+ frame1 = cv2.resize(frame1, (frame2.shape[1], frame2.shape[0]))
62
+
63
+ score, _ = compare_ssim(frame1, frame2, full=True, multichannel=True)
64
+
65
+ if score < 0.99:
66
+ return True
67
+
68
+ cap1.release()
69
+ cap2.release()
70
+ return False
71
+
72
+
73
  @functools.lru_cache
74
  def is_cuda_available():
75
  return torch.cuda.is_available()