-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data.py
60 lines (53 loc) · 1.94 KB
/
Data.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
import csv
from scipy import ndimage
import numpy as np
lines = [] # get list containing location of all images.
with open('data/driving_log.csv') as csvfile:
reader = csv.reader(csvfile)
for line in reader:
lines.append(line)
origimages = []
origmeasurements = []
correction = 0.2 # correction fcactor for left/ right camera images
for line in lines:
sourcepath = line[0] # for centre images
filename = sourcepath.split('/')[-1]
currentpath = 'Data/IMG/' + filename
image = ndimage.imread(currentpath)
flipimage = np.fliplr(image) # horizontally flip image
origimages.append(image)
origimages.append(flipimage)
measurement = float(line[3])
flipmeasurement = - measurement # negative of original reading for flopped image
origmeasurements.append(measurement)
origmeasurements.append(flipmeasurement)
for line in lines:
sourcepath = line[1] # for left image
filename = sourcepath.split('/')[-1]
currentpath = 'data/IMG/' + filename
image = ndimage.imread(currentpath)
flipimage = np.fliplr(image)
origimages.append(image)
origimages.append(flipimage)
measurement = float(line[3])
measurement = measurement + correction # correction added
flipmeasurement = - measurement
origmeasurements.append(measurement)
origmeasurements.append(flipmeasurement)
for line in lines:
sourcepath = line[2] # for right image
filename = sourcepath.split('/')[-1]
currentpath = 'data/IMG/' + filename
image = ndimage.imread(currentpath)
flipimage = np.fliplr(image)
origimages.append(image)
origimages.append(flipimage)
measurement = float(line[3])
measurement = measurement - correction
flipmeasurement = - measurement
origmeasurements.append(measurement)
origmeasurements.append(flipmeasurement)
origXTrain = np.array(origimages)
origYTrain = np.array(origmeasurements)
np.save('UXTrain1', origXTrain)
np.save('UYTrain1', origYTrain)