-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdemo_kitti.lua
108 lines (73 loc) · 3.13 KB
/
demo_kitti.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
------------------------------------------------------------------------------
-- This script loads the KITTI dataset
-- Aysegul Dundar
-- e-mail : adundar@purdue.edu
-- Date : 04/28/2013
------------------------------------------------------------------------------
-- Requires ------------------------------------------------------------------
require 'image' -- to visualize the dataset
require 'sys'
require 'xml'
require 'kitti2Dbox'
require 'qtwidget'
require 'qtuiloader'
require 'qt'
-- Exporting functions to the global namespace -------------------------------
local max = math.max
local min = math.min
-- Title ---------------------------------------------------------------------
print [[
********************************************************************************
>>>>>>>>>>>>>> Torch interface to KITTI (for cars) dataset <<<<<<<<<<<<<<<<<<<<<
********************************************************************************
]]
-- Global functions ----------------------------------------------------------
-- Parse XML
function parseXML(tracklet_labels)
local parse = xml.parse(tracklet_labels)
local tracklet = parse.boost_serialization.tracklets
return tracklet
end
-- Extract patches
function extractObjects(dspath, tracklet)
videoframes = #sys.dirname(dspath)-2 -- #sys.dir(dspath) == total number of frames in video dump (minum . and ..)
for imgi = 1,videoframes do
rawFrame = image.loadPNG(tostring(dspath..string.format("%010u", imgi-1)..'.png'))
if not win then
win = qtwidget.newwindow(rawFrame:size(3), rawFrame:size(2), 'KITTI city')
end
win:gbegin()
win:showpage()
sys.sleep(0.1)
image.display{image=rawFrame, win=win}
-- get bounding boxes from tracklets:
for k=1, tracklet.count do
first = tonumber(tracklet.item[k].first_frame)
count = tonumber(tracklet.item[k].poses.count)+first
if first<imgi and imgi<=count then
box = kitti2Dbox(tracklet.item[k].poses.item[imgi-first], tracklet.item[k])
box.objectType = tracklet.item[k].objectType
iwidth = rawFrame:size(3)
iheight = rawFrame:size(2)
box.x1 = max(1, min(iwidth, box.x1))
box.y1 = max(1, min(iheight, box.y1))
box.x2 = max(1, min(iwidth, box.x2))
box.y2 = max(1, min(iheight, box.y2))
win:setcolor(1,0,0)
win:rectangle(box.x1, box.y1, box.x2-box.x1, box.y2-box.y1)
win:setfont(qt.QFont{serif=false,italic=false,size=16})
win:moveto(box.x1, box.y1-1)
win:show(box.objectType)
win:stroke()
win:gend()
end
end
end
end
-- Main program -------------------------------------------------------------
print '==> loading KITTI tracklets and parsing the XML files'
local dspath = '/Users/eugenioculurciello/Code/datasets/KITTI/2011_09_26/2011_09_26_drive_0001_sync'
local img_path = dspath .. '/image_02/data/'
local tracklet_labels = xml.load(dspath .. '/tracklet_labels.xml')
local tracklet = parseXML(tracklet_labels)
extractObjects(img_path, tracklet)