-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
59 lines (49 loc) · 1.85 KB
/
index.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
50
51
52
53
54
55
56
57
58
59
# USAGE
# python index.py --dataset dataset --index index.csv
# import the necessary packages
from pyimagesearch.colordescriptor import ColorDescriptor
import argparse
import glob
import cv2
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dataset", required=True,
help = "Path to the directory that contains the images to be indexed")
ap.add_argument("-i", "--index", required=True,
help = "Path to where the computed index will be stored")
args = vars(ap.parse_args())
# initialize the color descriptor
cd = ColorDescriptor((8, 12, 3))
# open the output index file for writing
output = open(args["index"], "w")
# use glob to grab the image paths and loop over them
globpath = []
globpath = globpath + glob.glob(args["dataset"] + "/*.png")
globpath = globpath + glob.glob(args["dataset"] + "/*.jpg")
# for imagePath in glob.glob(args["dataset"] + "/*.png"):
for imagePath in globpath:
# extract the image ID (i.e. the unique filename) from the image
# path and load the image itself
# imageID = imagePath[imagePath.rfind("/") + 1:]
imageID = imagePath[imagePath.rfind("\\") + 1:]
image = cv2.imread(imagePath)
# describe the image
features = cd.describe(image)
# write the features to file
features = [str(f) for f in features]
output.write("%s,%s\n" % (imageID, ",".join(features)))
# for imagePath in glob.glob(args["dataset"] + "/*.jpg"):
# # extract the image ID (i.e. the unique filename) from the image
# # path and load the image itself
# # imageID = imagePath[imagePath.rfind("/") + 1:]
# imageID = imagePath[imagePath.rfind("\\") + 1:]
# image = cv2.imread(imagePath)
#
# # describe the image
# features = cd.describe(image)
#
# # write the features to file
# features = [str(f) for f in features]
# output.write("%s,%s\n" % (imageID, ",".join(features)))
# close the index file
output.close()