-
Notifications
You must be signed in to change notification settings - Fork 5
/
CUnsupKITTI.lua
executable file
·160 lines (113 loc) · 4.43 KB
/
CUnsupKITTI.lua
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
local unsupKITTI = torch.class('unsupKITTI')
function unsupKITTI:__init(baseFolder, setName, hpatch)
self.baseFolder = baseFolder;
self.crop = false -- crop images to standard size
if( setName == 'kitti_ext' or setName == 'kitti2015_ext' ) then
self.nbFrames = 20
else
self.nbFrames = 1
end
self.maxBatchSize = 370 - hpatch*2
self.setName = setName
self.hpatch = hpatch
self.height = 185
self.width = 1242;
self.nb_epi_per_image = 32;
if setName == 'kitti' or setName == 'kitti_ext' then
self.im0_fname = baseFolder .. '/%s/image_0/%06d_%02d.png'
self.im1_fname = baseFolder .. '/%s/image_1/%06d_%02d.png'
self.test_nbIm = 195
self.train_nbIm = 194
self.disp_max = 228 -- guessed from training data
self.nb_ch = 1;
elseif setName == 'kitti2015' or setName == 'kitti2015_ext' then
self.im0_fname = baseFolder .. '/%s/image_2/%06d_%01d.png'
self.im1_fname = baseFolder .. '/%s/image_3/%06d_%01d.png'
self.test_nbIm = 200
self.train_nbIm = 200
self.disp_max = 230
self.nb_ch = 3;
else
error('SetName should be equal to "kitti" or "kitti15"\n')
end
self.nbIm = (self.test_nbIm + self.train_nbIm)*self.nbFrames
end
function unsupKITTI:get( batch_size )
local nFrame, nImg, set, im0_fname, im1_fname, im1, im0, actual_height, actual_width
local tabWidth = {}
local tabDisp = {}
local epiRef = {}
local epiPos = {}
local epiNeg = {}
for nEpi = 1, batch_size do
tabDisp[nEpi] = self.disp_max
if( (nEpi-1) % self.nb_epi_per_image == 0 ) then
repeat
local n = (torch.random() % (self.nbIm)) + 1;
-- local n = self.imActive[idx]
-- self.imActive
-- get random image
--- local n = self.imActive[torch.random(1,self.nbImActive)]
if self.setName == 'kitti2015' or self.setName == 'kitti' then
nFrame = 10
nImg = n;
else
nFrame = n % self.nbFrames
nImg = math.floor(n / nFrame);
end
--print(nImg)
-- test or train?
if nImg < self.train_nbIm then
set = 'training'
nImg = nImg
else
set = 'testing'
nImg = nImg - self.train_nbIm;
end
--print(nImg)
-- images location
im0_fname = self.im0_fname:format(set, nImg, nFrame)
im1_fname = self.im1_fname:format(set, nImg, nFrame)
until ( utils.file_exists(im0_fname) and utils.file_exists(im1_fname) )
-- read image
im0 = image.loadPNG(im0_fname, self.nb_ch, 'byte'):float()
im1 = image.loadPNG(im1_fname, self.nb_ch, 'byte'):float()
-- cut ski
actual_width = im0:size(3)
actual_height = im0:size(2)
if self.crop then
im0 = im0:narrow(2, actual_height - self.height + 1, self.height)
im1 = im1:narrow(2, actual_height - self.height + 1, self.height)
end
actual_height = im0:size(2)
if( im0:size(3) ~= im1:size(3) ) then
error('image size')
end
-- convert to luminance
if self.setName == 'kitti2015' or self.setName == 'kitti2015_ext' then
im0 = image.rgb2y(im0)
im1 = image.rgb2y(im1)
end
-- normalize intensity
im0:add(-im0:mean()):div(im0:std())
im1:add(-im1:mean()):div(im1:std())
end
tabWidth[nEpi] = actual_width
-- get random epipolar line
local rowRefCent = torch.random(self.hpatch+1, actual_height-self.hpatch)
local rowMax = rowRefCent + self.hpatch;
local rowMin = rowRefCent - self.hpatch;
epiRef[nEpi] = im0[{{},{rowMin,rowMax},{}}]:double();
epiPos[nEpi] = im1[{{},{rowMin,rowMax},{}}]:double();
-- get random negative epipolar line
local rowNegCent
repeat
rowNegCent = torch.random(self.hpatch+1, actual_height-self.hpatch)
local rowDif = math.abs(rowNegCent-rowRefCent);
until (rowDif > self.hpatch)
rowMax = rowNegCent + self.hpatch;
rowMin = rowNegCent - self.hpatch;
epiNeg[nEpi] = im1[{{},{rowMin,rowMax},{}}]:double();
end
return {epiRef, epiPos, epiNeg}, tabWidth, tabDisp
end