-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkinect.lua
82 lines (70 loc) · 2.29 KB
/
kinect.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
----------------------------------
-- dependencies
----------------------------------
require 'torch'
require 'image'
require 'libkinect'
----------------------------------
-- package
----------------------------------
kinect = {}
-- Initializes the Kinect.
--
-- Args:
-- kinectParams - a table of kinect calibration parameters. These will,
-- generally speaking, be different for each Kinect device.
function kinect.init(kinectParams)
if not kinect.initialized then
kinect.rgb = torch.Tensor()
kinect.depth = torch.Tensor()
kinect.projDepth = torch.Tensor()
kinect.filtered = torch.Tensor()
kinect.params = kinectParams
torch.Tensor().kinect.init()
kinect.initialized = true
end
end
function kinect.stop()
local type = kinect.rgb
type.kinect.stop()
kinect.initialized = false
end
function kinect.getRGBD()
local type = kinect.rgb
type.kinect.getRGBD(kinect.rgb, kinect.depth)
return kinect.rgb, kinect.depth
end
function kinect.project(depth)
local type = kinect.rgb
type.kinect.project(depth, kinect.projDepth)
return kinect.projDepth
end
function kinect.projectPar(depth)
local type = kinect.rgb
type.kinect.project_par(depth, kinect.projDepth)
return kinect.projDepth
end
function kinect.filterCbf(depthProj, rgb)
local type = kinect.rgb
type.kinect.filterCbf(depthProj, rgb, kinect.filtered)
return kinect.filtered
end
----------------------------------
-- package a little demo
----------------------------------
kinect.testme = function()
print '--------------------------------------------------'
print 'grabbing frames from kinect'
kinect.init()
local fps = 0
for i = 1,200 do -- ~10 seconds
sys.tic()
local frame, depth = kinect.getRGBD()
w = image.display{image=frame, win=w, legend='rgb ['..fps..'fps]'}
wd = image.display{image=depth, win=wd, legend='depth ['..fps..'fps]'}
local t = sys.toc()
if fps == 0 then fps = 1/t end
fps = math.ceil((1/t + fps)/2)
end
print '--------------------------------------------------'
end