forked from sadmb/ofxKinectNui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofxKinectNui.h
269 lines (222 loc) · 7.71 KB
/
ofxKinectNui.h
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/******************************************************************/
/**
* @file ofxKinectNui.h
* @brief kinect nui wrapper for oF
* @note
* @todo
* @bug
*
* @author sadmb
* @date Oct. 26, 2011
*/
/******************************************************************/
#ifndef OFX_KINECT_NUI_H
#define OFX_KINECT_NUI_H
#include "kinect/nui/Kinect.h" // this should be before ofMain.h
#include "kinect/nui/ImageFrame.h" // for VideoFrame and DepthFrame
#include "ofMain.h"
#include "ofxBase3DVideo.h"
class IDrawPixels;
class IDrawPoints;
//////////////////////////////////////////////////////
// class declarations //
//////////////////////////////////////////////////////
/****************************************/
/**
* @class ofxKinectNui
* @brief kinect wrapper for oF
* @note
* @author sadmb
* @date Oct. 26, 2011
*/
/****************************************/
class ofxKinectNui: public ofxBase3DVideo{
public:
ofxKinectNui();
virtual ~ofxKinectNui();
struct InitSetting{
bool grabVideo:1;
bool grabDepth:1;
bool grabAudio:1;
bool grabLabel:1;
bool grabSkeleton:1;
bool grabCalibratedVideo:1;
bool grabLabelCv:1;
NUI_IMAGE_TYPE videoImageType;
NUI_IMAGE_RESOLUTION videoResolution;
NUI_IMAGE_RESOLUTION depthResolution;
InitSetting(){
grabVideo = true;
grabDepth = true;
grabAudio = false;
grabLabel = false;
grabSkeleton = false;
grabCalibratedVideo = false;
grabLabelCv = false;
videoImageType = NUI_IMAGE_TYPE_COLOR;
videoResolution = NUI_IMAGE_RESOLUTION_640x480;
depthResolution = NUI_IMAGE_RESOLUTION_320x240;
}
};
enum {
UPDATE_FLAG_NONE = 0x00000000,
UPDATE_FLAG_VIDEO = 0x00000001,
UPDATE_FLAG_DEPTH = 0x00000100,
UPDATE_FLAG_LABEL = 0x00000200,
UPDATE_FLAG_LABEL_CV = 0x00000400,
UPDATE_FLAG_DISTANCE = 0x00000800,
UPDATE_FLAG_CALIBRATED_VIDEO= 0x00001000,
UPDATE_FLAG_SKELETON = 0x00010000,
UPDATE_FLAG_AUDIO = 0x01000000,
UPDATE_FLAG_GROUP_VIDEO = 0x000000FF,
UPDATE_FLAG_GROUP_DEPTH = 0x0000FF00,
UPDATE_FLAG_GROUP_SKELETON = 0x00FF0000,
UPDATE_FLAG_GROUP_AUDIO = 0xFF000000,
UPDATE_FLAG_ALL = 0xFFFFFFFF,
};
static const int SKELETON_COUNT = NUI_SKELETON_COUNT;
static const int SKELETON_POSITION_COUNT = NUI_SKELETON_POSITION_COUNT;
bool init();
bool init(const InitSetting& setting);
bool init( bool grabVideo,
bool grabDepth,
bool grabAudio,
bool grabLabel,
bool grabSkeleton,
bool grabCalibratedVideo,
bool grabLabelCv,
NUI_IMAGE_TYPE videoImageType = NUI_IMAGE_TYPE_COLOR,
NUI_IMAGE_RESOLUTION videoResolution = NUI_IMAGE_RESOLUTION_640x480,
NUI_IMAGE_RESOLUTION depthResolution = NUI_IMAGE_RESOLUTION_320x240);
bool open();
void close();
void update(){update(UPDATE_FLAG_ALL);}
void update(UINT flag);
void setVideoDrawer(IDrawPixels* drawer);
void setDepthDrawer(IDrawPixels* drawer);
void setLabelDrawer(IDrawPixels* drawer);
void setSkeletonDrawer(IDrawPoints* drawer);
void drawVideo();
void drawDepth();
void drawLabel();
void drawSkeleton();
void drawVideo(int x, int y, int width, int height);
void drawDepth(int x, int y, int width, int height);
void drawLabel(int x, int y, int width, int height);
void pluggedFunc();
void unpluggedFunc();
void drawSkeleton(float x, float y, float w, float h);
void drawSkeleton(float x, float y);
void drawSkeleton(const ofPoint& point);
void drawSkeleton(const ofPoint& point, float w, float h);
void drawSkeleton(const ofRectangle& rect);
void setAngle(int angleInDegrees);
void setMirror(bool isMirror) { bIsMirror = isMirror; }
void setNearmode(bool isNearmode) { bIsNearmode = isNearmode; }
int getCurrentAngle();
int getTargetAngle();
ofPixels& getVideoPixels();
ofPixels& getDepthPixels();
ofPixels& getLabelPixels();
ofPixels& getCalibratedVideoPixels();
ofPixels& getLabelPixelsCv(int playerId);
ofPixels* getLabelPixelsCvArray();
ofShortPixels& getDistancePixels();
std::vector<BYTE> getSoundBuffer();
int getSkeletonPoints(ofPoint* ret[]);
int getRawSkeletonPoints(ofPoint* ret[]);
ofColor getColorAt(int x, int y);
ofColor getColorAt(const ofPoint& point);
ofColor getCalibratedColorAt(int depthX, int depthY);
ofColor getCalibratedColorAt(const ofPoint& depthPoint);
ofPoint getWorldCoordinateFor(int depthX, int depthY);
unsigned short getDistanceAt(int depthX, int depthY);
unsigned short getDistanceAt(const ofPoint& depthPoint);
int getPlayerIndexAt(int depthX, int depthY);
int getPlayerIndexAt(const ofPoint& point);
float getAudioBeamAngle();
float getAudioAngle();
float getAudioAngleConfidence();
bool isFrameNew();
bool isInited();
bool isConnected();
bool isOpened();
bool isNearmode();
bool isFoundSkeleton();
bool isTrackedSkeleton(int id);
bool isMirror();
bool grabsVideo();
bool grabsDepth();
bool grabsLabel();
bool grabsSkeleton();
bool grabsAudio();
bool grabsCalibratedVideo();
bool grabsLabelCv();
NUI_IMAGE_RESOLUTION getVideoResolution();
NUI_IMAGE_RESOLUTION getDepthResolution();
NUI_IMAGE_TYPE getVideoImageType();
int getVideoResolutionWidth();
int getVideoResolutionHeight();
int getDepthResolutionWidth();
int getDepthResolutionHeight();
void enableDepthNearValueWhite(bool bEnabled);
bool isDepthNearValueWhite();
template<class T> void addKinectListener(T* object, void(T::*pluggedFunction)(), void(T::*unpluggedFunction)())
{
kinect.AddKinectListener(object, pluggedFunction, unpluggedFunction);
}
template<class T> void removeKinectListener(T* object)
{
kinect.RemoveKinectListener(object);
}
public:
const static int KINECT_PLAYERS_INDEX_NUM = 8;
static int getActiveCount(){
return kinect::nui::Kinect::GetActiveCount();
}
static int getAvailableCount(){
return kinect::nui::Kinect::GetAvailableCount();
}
static int getConnectedCount(){
return kinect::nui::Kinect::GetConnectedCount();
}
static int getNextAvailableIndex(){
return kinect::nui::Kinect::GetNextAvailableIndex();
}
protected:
kinect::nui::Kinect kinect; ///< kinect instance
ofPixels videoPixels; ///< video pixels
ofPixels depthPixels; ///< depth pixels
ofShortPixels distancePixels; ///< distance pixels (raw depth pixels data from sensor)
ofPixels labelPixels; ///< label pixels
ofPixels calibratedVideoPixels; ///< video pixels adjusted to depth pixels
ofPixels labelPixelsCv[KINECT_PLAYERS_INDEX_NUM]; ///< separated label pixels for cv use, labelPixelsCv[0] contains whole players silhouette. labelPixelsCv[playerId] contains each players silhouette.
std::vector<BYTE> soundBuffer; ///< audio buffer
float audioBeamAngle, audioAngle, audioAngleConfidence; ///< for audio
ofPoint skeletonPoints[SKELETON_COUNT][SKELETON_POSITION_COUNT]; ///< joint points of all skeletons
ofPoint rawSkeletonPoints[SKELETON_COUNT][SKELETON_POSITION_COUNT]; ///< joint points of all skeletons
int targetAngle; ///< target angle of kinect tilt
bool bIsOpened; ///< is stream opened?
bool bIsInited; ///< is kinect initialized?
bool bIsNearmode; ///< is kinect nearmode?
bool bGrabsVideo; ///< grabs video?
bool bGrabsDepth; ///< grabs depth?
bool bGrabsAudio; ///< grabs audio?
bool bGrabsLabel; ///< grabs label?
bool bGrabsSkeleton; ///< grabs skeleton?
bool bGrabsCalibratedVideo; ///< grabs calibrated video?
bool bGrabsLabelCv; ///< grabs separated label for cv?
bool bIsMirror; ///< is mirror mode
bool bIsFrameNew; ///< frame updated?
bool bIsFoundSkeleton;
NUI_IMAGE_TYPE mVideoImageType; ///< video image type
NUI_IMAGE_RESOLUTION mVideoResolution; ///< video resolution flag
NUI_IMAGE_RESOLUTION mDepthResolution; ///< depth resolution flag
int mVideoBpp;
UINT updateFlagDefault_;
IDrawPixels* videoDraw_;
IDrawPixels* depthDraw_;
IDrawPixels* labelDraw_;
IDrawPoints* skeletonDraw_;
};
#endif // OFX_KINECT_NUI_H