-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_dups.py
50 lines (38 loc) · 1.18 KB
/
remove_dups.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from utils import cache_object, app_prep, load_image_from_url
import traceback
import imagehash
import logging as log
def main():
log.info( "Caching all images in memory " )
c1 = cache_object( 'group2.moderate' )
#hashfunc = imagehash.average_hash
hashfunc = imagehash.phash
#hashfunc = imagehash.dhash
images = {}
for url in c1:
img = load_image_from_url(url)
if (img):
hash = hashfunc( img )
images[hash] = images.get(hash, []) + [url]
else:
log.warning( url + " not loaded" )
log.info( "Caching done" )
for k, img_list in images.iteritems():
if len(img_list) > 1:
saved_one = False
log.info("--------------Duplicates------------------")
for img in img_list:
if (saved_one):
c1.remove(img)
log.info(img)
saved_one = True
c1.save()
if __name__ == "__main__":
app_prep( 'remove_dups.log' )
try:
main()
except Exception as e:
for line in traceback.format_exc().splitlines():
log.error( line )