-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathOpenNI2Stream.lua
69 lines (56 loc) · 2.13 KB
/
OpenNI2Stream.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
local ffi = require 'ffi'
local torch = require 'torch'
local pcl = require 'pcl.PointTypes'
local utils = require 'pcl.utils'
local OpenNI2Stream = torch.class('pcl.OpenNI2Stream', pcl)
local func_by_type = {}
local function init()
local OpenNI2Stream_method_names = { 'new', 'delete', 'start', 'stop', 'read', 'readRGBImage', 'readDepthImage', 'readIRImage' }
local base_name = 'pcl_OpenNI2Stream_XYZRGB_'
local supported_types = {}
supported_types[pcl.PointXYZ] = "XYZ"
supported_types[pcl.PointXYZI] = "XYZI"
supported_types[pcl.PointXYZRGBA] = "XYZRGBA"
for k,v in pairs(supported_types) do
func_by_type[k] = utils.create_typed_methods("pcl_OpenNI2Stream_TYPE_KEY_", OpenNI2Stream_method_names, v)
end
end
init()
function OpenNI2Stream:__init(pointType, device_id, max_backlog, grab_RGB, grab_depth, grab_IR)
device_id = device_id or ''
max_backlog = max_backlog or 2
self.pointType = pcl.pointType(pointType)
self.f = func_by_type[self.pointType]
self.o = self.f.new(device_id, max_backlog, grab_RGB or false, grab_depth or false, grab_IR or false)
ffi.gc(self.o, self.f.delete)
end
function OpenNI2Stream:start()
self.f.start(self.o);
end
function OpenNI2Stream:stop()
self.f.stop(self.o);
end
function OpenNI2Stream:read(timeout_milliseconds)
timeout_milliseconds = timeout_milliseconds or 1000
local frame = self.f.read(self.o, timeout_milliseconds)
if frame ~= nil then
frame = pcl.PointCloud(self.pointType, frame)
ffi.gc(frame:cdata(), rawget(frame, 'f').delete)
end
return frame
end
function OpenNI2Stream:readRGBImage(timeout_milliseconds, result)
result = result or torch.ByteTensor()
self.f.readRGBImage(self.o, timeout_milliseconds or 1000, result:cdata())
return result
end
function OpenNI2Stream:readDepthImage(timeout_milliseconds, result)
result = result or torch.ShortTensor()
self.f.readDepthImage(self.o, timeout_milliseconds or 1000, result:cdata())
return result
end
function OpenNI2Stream:readIRImage(timeout_milliseconds, result)
result = result or torch.ShortTensor()
self.f.readIRImage(self.o, timeout_milliseconds or 1000, result:cdata())
return result
end