-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_database.py
More file actions
33 lines (29 loc) · 853 Bytes
/
create_database.py
File metadata and controls
33 lines (29 loc) · 853 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
import cv2
import cPickle
def store_contour(img, s):
_, thresh = cv2.threshold(img, 100, 255, 0)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
maxarea = 0
pos = -1
for i in range(len(contours)):
area = cv2.contourArea(contours[i])
if area > maxarea:
maxarea = area
pos = i
cnt = contours[pos]
fileName = "ITSP_database/" + s + ".txt"
f = open(fileName, "w")
f.write(cPickle.dumps(cnt))
f.close()
letters = [chr(i) for i in range(65, 90) if i != 74]
for x in range(10):
letters.append(str(x))
for l in letters:
imageName = "ITSP_templates3/" + l + ".png"
print imageName
image = cv2.imread(imageName, 0)
store_contour(image, l)
# print "INDEX:"
#
# index = cPickle.loads(open("output.txt").read())
# print index