-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.py
30 lines (24 loc) · 826 Bytes
/
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
# USAGE
# python index.py --dir image
from imagesearch.colordescriptor import ColorDescriptor
import argparse
import glob
import cv2
import sqlite3
ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dir", required = True,
help = "Path to the dir that contains the images to be indexed")
args = vars(ap.parse_args())
cd = ColorDescriptor((8, 12, 3))
con = sqlite3.connect(".\\index.db")
cu = con.cursor()
cu.execute("CREATE TABLE imageindex(filename text primary key,features text)")
con.commit()
for imagePath in glob.glob(args["dir"] + "\\*.png"):
imageID = imagePath[imagePath.rfind("\\") + 1:]
image = cv2.imread(imagePath)
features = cd.describe(image)
data = (imageID, str(features))
cu.execute("INSERT INTO imageindex(filename, features) values (?, ?)", data)
con.commit()
con.close()