-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequential_ImageHash.py
More file actions
39 lines (30 loc) · 1005 Bytes
/
Sequential_ImageHash.py
File metadata and controls
39 lines (30 loc) · 1005 Bytes
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
import json
from PIL import Image
import imagehash
import time
from imutils import paths
import numpy as np
def convert_hash(h):
return str(np.array(h))
def process_images(payload):
print("starting process")
hashes = {}
for imagePath in payload:
image = Image.open(imagePath)
image_hash = imagehash.average_hash(image)
image_hash = convert_hash(image_hash)
hash_list = hashes.get(image_hash, [])
hash_list.append(imagePath)
hashes[image_hash] = hash_list
print("process {} serializing".format("seq"))
f = open("output\\process_seq.json", "w")
f.write(json.dumps(hashes))
f.close()
if __name__ == "__main__":
start_time = time.time()
print("grabbing image paths")
allImagePaths = sorted(list(paths.list_images('Input_Images')))
print("waiting for procs to finish...")
process_images(allImagePaths)
print("time taken")
print(time.time() - start_time)