-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkinect.cpp
63 lines (51 loc) · 1.57 KB
/
kinect.cpp
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
#include <glog/logging.h>
#include "kinect.h"
kinect::kinect() : _max_depth(0), _buffer_size(0) {}
kinect::~kinect() {
if (_depth_generator)
_depth_generator.Release();
_ctx.Release();
LOG(INFO) << "kinect::~kinect()";
}
void kinect::setup() {
xn::EnumerationErrors errors;
XnStatus status = XN_STATUS_OK;
status = _ctx.Init();
if (status != XN_STATUS_OK) {
for (xn::EnumerationErrors::Iterator it = errors.Begin();
it != errors.End(); ++it) {
XnChar desc[512];
xnProductionNodeDescriptionToString(&it.Description(), desc, 512);
LOG(ERROR) << desc << " failed to to enumerate: "
<< xnGetStatusString(it.Error());
}
}
xnPrintRegisteredLicenses();
status = _ctx.FindExistingNode(XN_NODE_TYPE_DEPTH, _depth_generator);
if (status != XN_STATUS_OK) {
status = _depth_generator.Create(_ctx);
}
if (status != XN_STATUS_OK) {
LOG(ERROR) << "couldnt get a depth generator";
throw 20;
} else {
XnMapOutputMode map_mode;
map_mode.nXRes = XN_VGA_X_RES;
map_mode.nYRes = XN_VGA_Y_RES;
map_mode.nFPS = 30;
_buffer_size = map_mode.nXRes * map_mode.nYRes;
status = _depth_generator.SetMapOutputMode(map_mode);
_max_depth = _depth_generator.GetDeviceMaxDepth();
_depth_generator.StartGenerating();
}
}
const XnDepthPixel *kinect::get_depthmap_pointer() {
XnStatus status = _depth_generator.WaitAndUpdateData();
if (status != XN_STATUS_OK) {
throw 69;
}
xn::DepthMetaData dmd;
_depth_generator.GetMetaData(dmd);
const XnDepthPixel *_map = dmd.Data();
return _map;
}