From c02f40703f6fee81fe6d82b91318b54a614ef111 Mon Sep 17 00:00:00 2001 From: lijianshe02 Date: Fri, 25 Sep 2020 03:47:30 +0000 Subject: [PATCH] add remove duplicate frames in DAIN --- applications/DAIN/predict.py | 6 ------ applications/DAIN/util.py | 18 +++++++++--------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/applications/DAIN/predict.py b/applications/DAIN/predict.py index 3a8294e..3929043 100644 --- a/applications/DAIN/predict.py +++ b/applications/DAIN/predict.py @@ -202,12 +202,6 @@ class VideoFrameInterp(object): X0 = img_first.astype('float32').transpose((2, 0, 1)) / 255 X1 = img_second.astype('float32').transpose((2, 0, 1)) / 255 - #if key_frame: - # y_ = [ - # np.transpose(255.0 * X0.clip(0, 1.0), (1, 2, 0)) - # for i in range(num_frames) - # ] - #else: assert (X0.shape[1] == X1.shape[1]) assert (X0.shape[2] == X1.shape[2]) diff --git a/applications/DAIN/util.py b/applications/DAIN/util.py index 2bd98e4..dc343ff 100644 --- a/applications/DAIN/util.py +++ b/applications/DAIN/util.py @@ -48,24 +48,24 @@ def combine_frames(input, interpolated, combined, num_frames): def remove_duplicates(paths): - def dhash(image, hashSize=8): + def dhash(image, hash_size=8): gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) - resized = cv2.resize(gray, (hashSize + 1, hashSize)) + resized = cv2.resize(gray, (hash_size + 1, hash_size)) diff = resized[:, 1:] > resized[:, :-1] return sum([2**i for (i, v) in enumerate(diff.flatten()) if v]) hashes = {} - imagePaths = sorted(glob.glob(os.path.join(paths, '*.png'))) - for imagePath in imagePaths: - image = cv2.imread(imagePath) + image_paths = sorted(glob.glob(os.path.join(paths, '*.png'))) + for image_path in image_paths: + image = cv2.imread(image_path) h = dhash(image) p = hashes.get(h, []) - p.append(imagePath) + p.append(image_path) hashes[h] = p - for (h, hashedPaths) in hashes.items(): - if len(hashedPaths) > 1: - for p in hashedPaths[1:]: + for (h, hashed_paths) in hashes.items(): + if len(hashed_paths) > 1: + for p in hashed_paths[1:]: os.remove(p) frames = sorted(glob.glob(os.path.join(paths, '*.png'))) -- GitLab