-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadImages.py
128 lines (100 loc) · 3.01 KB
/
loadImages.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#Steven
import os
import cv2
import numpy as np
from numpy import save,load
from genLabel import getLabelFileLabels,newW,newH
def loadImg(file,mode=cv2.IMREAD_COLOR):
#mode = cv2.IMREAD_COLOR cv2.IMREAD_GRAYSCALE cv2.IMREAD_UNCHANGED
return cv2.imread(file,mode)
def getImgHW(img):
return img.shape[0],img.shape[1]
def getImgShape(img):
return img.shape
def fileList(file):
with open(file,'r') as srcF:
return srcF.readlines()
gStartIndex = 0
gBachSize=10
gLines = []
def getDataBatch(file,bachSize=10):
global gStartIndex
global gBachSize
global gLines
gBachSize = bachSize
if len(gLines) == 0:
gLines = fileList(file)
size = len(gLines)
print('len=',size,type(gLines))
#trainX = np.empty([newH,newW],dtype=int)
#trainY = np.empty([68,2])
# trainX = np.empty([newH,newW],dtype=int)
# trainY = np.empty([68,2])
trainX = []
trainY = []
for _ in range(gStartIndex,gStartIndex+gBachSize):
i = gLines[gStartIndex].strip().split(',')
#print('i0=',i[0])
#print('i1=',i[1])#print(type(i),i)
fImg = i[0]
label=i[1]
img = loadImg(fImg)
H,W = getImgHW(img)
print(H,W,type(img),getImgShape(img),img[:,:,0].shape)
#trainX = np.concatenate((trainX, img[:,:,0]), axis=0)
trainX.append(img[:,:,0])
pts = getLabelFileLabels(label)
pts = np.array(pts).flatten()
#print(pts,pts.shape)
#trainY = np.concatenate((trainY, pts), axis=0)
trainY.append(pts)
gStartIndex +=1
gStartIndex = gStartIndex%size
print('gStartIndex=',gStartIndex)
return trainX,trainY
def getData(file):
lines = fileList(file)
size = len(lines)
print('len=',size,type(lines))
trainX = []
trainY = []
for _ in range(size):
i = lines[_].strip().split(',')
#print('i0=',i[0])
#print('i1=',i[1])#print(type(i),i)
fImg = i[0]
label=i[1]
img = loadImg(fImg)
H,W = getImgHW(img)
#print(H,W,type(img),getImgShape(img),img[:,:,0].shape)
#trainX = np.concatenate((trainX, img[:,:,0]), axis=0)
trainX.append(img[:,:,0])
pts = getLabelFileLabels(label)
pts = np.array(pts).flatten()
#print(pts,pts.shape)
#trainY = np.concatenate((trainY, pts), axis=0)
trainY.append(pts)
trainX=np.asarray(trainX)
trainY=np.asarray(trainY)
return trainX,trainY
def saveDataset():
file = r'.\db\train\trainList.list'
print(newW,newH)
x,y = getData(file)
print(x.shape)
print(y.shape)
save('./db/dataImg.npy', x)
save('./db/dataLabel.npy', y)
return
def loadDataset():
x = load(r'./db/dataImg.npy')
y = load(r'./db/dataLabel.npy')
print(x.shape)
print(y.shape)
return x,y
def main():
#saveDataset()
#loadDataset()
pass
if __name__=='__main__':
main()