-
Notifications
You must be signed in to change notification settings - Fork 0
/
unpack_images.py
45 lines (29 loc) · 1007 Bytes
/
unpack_images.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
import cv2
import csv
import matplotlib.image as mpimg
import myplot
from joblib import Parallel, delayed
rel_path = './images/udacity/object-detection-crowdai/'
def extract_single(row):
if row[0] == 'xmin':
return
xmin = int(row[0])
ymin = int(row[1])
xmax = int(row[2])
ymax = int(row[3])
file = row[4]
label = row[5]
if label == 'Car':
try:
img = mpimg.imread(rel_path + file)
car_img = img[ymin:ymax, xmin:xmax, :]
# myplot.plot(car_img)
resized = cv2.resize(car_img, (64, 64))
file_name = rel_path + '../extracted2/{}-{},{}.png'.format(file, xmin, ymin)
mpimg.imsave(file_name, resized)
except:
print('errored looking in file {}'.format(file))
if __name__ == '__main__':
with open(rel_path + 'labels.csv') as csvfile:
reader = csv.reader(csvfile)
Parallel(n_jobs=8, verbose=1)(delayed(extract_single) (row) for row in reader)