forked from JunhaoGao/detect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNegcut
More file actions
52 lines (50 loc) · 2.19 KB
/
Copy pathNegcut
File metadata and controls
52 lines (50 loc) · 2.19 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
import os
import cv2
import time
NegPath='C:\\detectProject\\Neg\\Negdata'
for root, dirs, files in os.walk(NegPath):
for negData in files:
print negData
myfile = open(NegPath+"\\"+negData)
allWords = []
line = myfile.readline()
i=0
c=0
while line:
if(c>1480):break
rec = line.split(',')
c = c + 1
if(c%3==0):
for i in range(0,len(rec)-1):
data=rec[i].split(' ')
xmin=data[0]
ymin=int(data[1])+140
xmax=data[2]
ymax=int(data[3])+140
model=data[4].split('_')
if(model[0]=="small" ):size='S'
if(model[0]=="middle"):size='M'
if(model[0]=="large" ):size='L'
if(model[1]=="front" ):Model='front'
if(model[1]=="side"):Model='side'
if(model[1]=="ride" ):Model='ride'
print xmin,xmax,ymin,ymax
path="C:/detectProject/Neg/frame/"+str(c-1)+".jpg"
img = cv2.imread(path)
# cv2.waitKey(0)
if( not img is None):
img2 = img[int(ymin):int(ymax), int(xmin):int(xmax)]
if(size=='S'):
img2=cv2.resize(img2,(50,100))
if(size=='M'):
img2=cv2.resize(img2,(100,200))
if(size=='L'):
img2=cv2.resize(img2,(200,400))
if(not cv2.imwrite("C:/detectProject/Neg/Negcut/" + Model+"/"+ size+str(c-1)+'FILE'+ str(i)+time.strftime(('-%m-%d-%H-%M'),time.localtime(time.time())) +'.jpg', img2) is None):
print "C:/detectProject/Neg/Negcut/" + Model+"/"+ size+str(c-1)+'FILE'+ str(i)+time.strftime(('-%m-%d-%H-%M'),time.localtime(time.time())) +'.jpg'
# if word[-1] == ',':
# #allWords.append(word[:-1])
# else:
# allWords.append(word)
line = myfile.readline()
myfile.close()