-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndex_images.py
29 lines (26 loc) · 1.03 KB
/
Index_images.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
# before index of images,please install PIL.
# import the necessary packages
from PIL import Image
import imagehash
import argparse
import shelve
import glob
# construct the argument parse and parse the arguments
ap = argument.ArgumentParser()
ap.add_argument("-d","--dataset",required = True,help="path to input dadaset of images" )
ap.add_argument("-s","--shelve", required = True, help ="output shelve database")
args = vars(ap.parse_args())
# open the shelve datebase
db = shelve.open(args["shelve"],writeback = True)
# loop over the image dataset
for imagePath in glob.glob(args["dataset"] + "/*.jpg"):
# load the image and compute the difference hash
image = Image.open(imagePath)
# Understand:h = str(imagehash.dhash())
h = str(imagehash.dhash(image))
# extract the filename from the path and update the database
# using the hash as the key and the filename append to the list of the values
filename = imagePath[imagePath.rfind("/") + 1:]
db[h] = db.get(h,[]) + [filename]
# close the shelve database
db.close()