Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(preprocessor): fix ffmpeg to deal with broken image
Browse files Browse the repository at this point in the history
  • Loading branch information
Larryjianfeng committed Jul 26, 2019
1 parent da77892 commit 7e43d5a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions gnes/preprocessor/video/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,27 @@ def pic_weight(images: List['np.ndarray']) -> List[float]:

def duplicate_rm_hash(self,
images: List['np.ndarray']) -> List['np.ndarray']:
hash_list = [phash_descriptor(_) for _ in images]
hash_list = []
for _ in images:
try:
hash_list.append(phash_descriptor(_))
except Exception:
hash_list.append(False)
self.logger.info('Broken image: ignored !')
ret = []
for i, h in enumerate(hash_list):
flag = 1
if len(ret) >= 1:
# only keep images with high phash diff
# comparing only last kept 9 pics
for j in range(1, min(len(ret) + 1, 9)):
dist = abs(ret[-j][1] - h)
if dist < self.phash_thresh:
flag = 0
break
if h:
for j in range(1, min(len(ret) + 1, 9)):
dist = abs(ret[-j][1] - h)
if dist < self.phash_thresh:
flag = 0
break
else:
flag = 0
if flag:
ret.append((i, h))

Expand Down

0 comments on commit 7e43d5a

Please sign in to comment.