-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaircursor.h
160 lines (115 loc) · 4.79 KB
/
aircursor.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
/*
Air Cursor library for Qt applications using Kinect
Copyright (C) 2012 Tuomas Haapala, Nemein
Quick instructions:
1. Make sure dependencies (OpenNI, Nite, OpenCV) are included in your .pro file
2. Add aircursor.h and aircursor.cpp to your project
3. Instantiate AirCursor class in your code
4. Call AirCursor::init()
5. Connect AirCursor signals to your QObjects
6. Call AirCursor::start()
*/
#ifndef AIRCURSOR_H
#define AIRCURSOR_H
#include <QThread>
#include <QMutex>
#include <QImage>
#include <iostream>
#include <XnOpenNI.h>
#include <XnVNite.h>
#include <cv.h>
class AirCursor : public QThread
{
Q_OBJECT
public:
explicit AirCursor(QObject *parent = 0);
~AirCursor();
bool init(bool makeDebugImage = false);
virtual void run();
void stop();
signals:
// most of these signals are straight equivalents of openni/nite callbacks
// emitted when hand tracking starts/stops
void handCreate(qreal x, qreal y, qreal z, qreal time);
void handDestroy(qreal time);
// emitted when full focus gesture is detected
void gestureRecognized(QString gestureStr);
// emitted when partial focus gesture is detected
void gestureProcess(QString gestureStr);
// emitted when hand tracking session starts/stops
void sessionStart();
void sessionEnd();
// emitted when hand position is updated
void handUpdate(qreal x, qreal y, qreal z, qreal time, bool grab);
// emitted when push gesture is detected
void push(qreal x, qreal y, qreal z, qreal velocity, qreal angle);
// emitted when grab state changes
void grab(qreal x, qreal y, qreal z);
void grabRelease(qreal x, qreal y, qreal z);
// emitted when hand is too near/far
void handTooClose();
void handTooFar();
// emitted when debug image is updated
void debugUpdate(QImage image, QList<QString> strings);
// emitted when swipe gesture is detected
void swipeUp(qreal velocity, qreal angle);
void swipeDown(qreal velocity, qreal angle);
void swipeLeft(qreal velocity, qreal angle);
void swipeRight(qreal velocity, qreal angle);
private:
void analyzeGrab();
void updateState();
void newHandPoint(qreal x, qreal y, qreal z);
// callbacks
static void XN_CALLBACK_TYPE gestureRecognizedCB(xn::GestureGenerator& generator,
const XnChar* strGesture,
const XnPoint3D* pIDPosition,
const XnPoint3D* pEndPosition, void* pCookie);
static void XN_CALLBACK_TYPE gestureProcessCB(xn::GestureGenerator& generator,
const XnChar* strGesture,
const XnPoint3D* pPosition,
XnFloat fProgress,
void* pCookie);
static void XN_CALLBACK_TYPE handCreateCB(xn::HandsGenerator& generator,
XnUserID nId, const XnPoint3D* pPosition,
XnFloat fTime, void* pCookie);
static void XN_CALLBACK_TYPE handUpdateCB(xn::HandsGenerator& generator,
XnUserID nId, const XnPoint3D* pPosition,
XnFloat fTime, void* pCookie);
static void XN_CALLBACK_TYPE handDestroyCB(xn::HandsGenerator& generator,
XnUserID nId, XnFloat fTime,
void* pCookie);
static void XN_CALLBACK_TYPE sessionStartCB(const XnPoint3D& pFocus, void* UserCxt);
static void XN_CALLBACK_TYPE sessionEndCB(void* UserCxt);
static void XN_CALLBACK_TYPE pushCB(XnFloat fVelocity, XnFloat fAngle, void *UserCxt);
static void XN_CALLBACK_TYPE swipeUpCB(XnFloat fVelocity, XnFloat fAngle, void* cxt);
static void XN_CALLBACK_TYPE swipeDownCB(XnFloat fVelocity, XnFloat fAngle, void* cxt);
static void XN_CALLBACK_TYPE swipeLeftCB(XnFloat fVelocity, XnFloat fAngle, void* cxt);
static void XN_CALLBACK_TYPE swipeRightCB(XnFloat fVelocity, XnFloat fAngle, void* cxt);
QList<XnPoint3D> m_handPoints;
xn::Context m_context;
xn::GestureGenerator m_gestureGenerator;
xn::HandsGenerator m_handsGenerator;
XnVSessionManager m_sessionManager;
xn::DepthGenerator m_depthGenerator;
XnVPushDetector m_pushDetector;
XnVSwipeDetector m_swipeDetector;
bool m_init;
XnDepthPixel* m_depthMap;
bool m_grabbing;
int m_grabCounter;
CvMemStorage* m_cvMemStorage;
IplImage* m_iplDepthMap;
IplImage* m_iplDebugImage;
bool m_quit;
XnPoint3D m_handPosRealWorld;
XnPoint3D m_handPosProjected;
XnPoint3D m_handPosSmooth;
QImage* m_debugImage;
bool m_debugImageEnabled;
XnPoint3D m_grabStarted;
bool m_grabDetected;
bool m_currentGrab;
qreal m_runningGrab;
};
#endif // AIRCURSOR_H