-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateDatabase.py
More file actions
62 lines (42 loc) · 1.3 KB
/
CreateDatabase.py
File metadata and controls
62 lines (42 loc) · 1.3 KB
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
60
61
import cv2 as cv
import os
import numpy as np
import string
def strcmp(left, right):
length_of_left, length_of_right = len(left), len(right)
result = 0
for index in range(length_of_left):
try:
if left[index] > right[index]:
result = 1
elif left[index] < right[index]:
result = 0
except (IndexError,):
result = 1
break
return 0 if length_of_right > length_of_left else result
def CreateDatabase(TrainDatabase = 'TrainDatabase'):
Train_Number = 0
TrainFiles = os.listdir('TrainDatabase')
for i in range(0, len(TrainFiles)):
if not(strcmp(TrainFiles[i], '.') & strcmp(TrainFiles[i], '..') & strcmp(TrainFiles[i], 'Thumbs.db')):
Train_Number += 1
T = []
for i in range(1, Train_Number):
str_i = str(i)
str_i = '\\' + str_i + '.jpg'
str_path = 'TrainDatabase\\' + str_i
img = cv.imread(str_path)
img = cv.cvtColor(img, 10)
# print(img.shape)
irow, icol = img.shape
temp = img.reshape(irow * icol, 1)
T.append(temp)
T = np.array(T)
T = np.squeeze(T)
T = T.T
return T
# cv.imshow('img', img)
# cv.waitKey(0)
# cv.destroyAllWindows()
CreateDatabase()