Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 32a6439

Browse files
committed
Added ipcQTgesture to the project.
1 parent ea05e62 commit 32a6439

File tree

7 files changed

+458
-0
lines changed

7 files changed

+458
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ A simple Qt/OpenCV example that displays an image and the RGB values of a pixel
1818
cvQTcameraGL
1919
--------------
2020
This application uses OpenCV to retrieve frames from the camera and display them on a QGLWidget.
21+
22+
ipcQTgesture
23+
--------------
24+
A Qt application that uses UtilPipeline (Intel® Perceptual Computing SDK 2013) for gesture recognition. This one is Windows only!

ipcQTgesture/gesture_handler.cpp

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
#include "gesture_handler.h"
2+
3+
#include <iostream>
4+
5+
#include <QImage>
6+
7+
8+
GestureHandler::GestureHandler()
9+
: _streaming(false), _init_error(false),
10+
_last_gesture(PXCGesture::Gesture::LABEL_ANY)
11+
{
12+
QObject::connect(&_fps_timer, SIGNAL(timeout()), this, SLOT(_stream()));
13+
14+
_pipeline.EnableImage(PXCImage::COLOR_FORMAT_RGB24);
15+
_pipeline.EnableGesture();
16+
17+
if (!_pipeline.Init())
18+
{
19+
std::cout << "GestureHandler::GestureHandler !!! Failed initializing pipeline." << std::endl;
20+
_init_error = true;
21+
}
22+
}
23+
24+
GestureHandler::~GestureHandler()
25+
{
26+
if (_init_error)
27+
return;
28+
29+
stop();
30+
_pipeline.Close();
31+
_pipeline.Release();
32+
}
33+
34+
bool GestureHandler::start()
35+
{
36+
if (_init_error)
37+
return false;
38+
39+
if (!_streaming)
40+
{
41+
_streaming = true;
42+
_elapsed_timer.start();
43+
_fps_timer.start(1000/30);
44+
}
45+
46+
return true;
47+
}
48+
49+
void GestureHandler::stop()
50+
{
51+
if (_init_error || !_streaming)
52+
return;
53+
54+
_streaming = false;
55+
_fps_timer.stop();
56+
}
57+
58+
QSize GestureHandler::image_size()
59+
{
60+
if (_init_error)
61+
return QSize();
62+
63+
pxcU32 img_w = 0, img_h = 0;
64+
if (!_pipeline.QueryImageSize(PXCImage::IMAGE_TYPE_COLOR, img_w, img_h))
65+
return QSize();
66+
67+
//std::cout << "GestureHandler::image_size Video Image size:" <<
68+
// img_w << "x" << img_h << std::endl;
69+
70+
return QSize(img_w, img_h);
71+
}
72+
73+
/*
74+
*_stream() reads a single frame
75+
*/
76+
void GestureHandler::_stream()
77+
{
78+
if (!_pipeline.AcquireFrame(true)) // true - blocking
79+
return;
80+
81+
// Retrieve QueryImage() as PXCSmartPtr<PXCImage> will crash later on
82+
PXCImage* image = _pipeline.QueryImage(PXCImage::IMAGE_TYPE_COLOR);
83+
84+
PXCImage::ImageData image_data;
85+
pxcStatus sts = image->AcquireAccess(PXCImage::ACCESS_READ,
86+
PXCImage::COLOR_FORMAT_RGB24,
87+
&image_data);
88+
if (sts < PXC_STATUS_NO_ERROR)
89+
{
90+
std::cout << "!!! Failed AcquireAccess." << std::endl;
91+
_pipeline.ReleaseFrame();
92+
return;
93+
}
94+
95+
PXCImage::ImageInfo image_info;
96+
image->QueryInfo(&image_info);
97+
if (sts < PXC_STATUS_NO_ERROR)
98+
{
99+
std::cout << "!!! Failed QueryInfo." << std::endl;
100+
_pipeline.ReleaseFrame();
101+
return;
102+
}
103+
104+
if (image_info.format == PXCImage::COLOR_FORMAT_RGB24)
105+
{ // BGR layout on little-endian machine
106+
unsigned char* bgr_img_data = (unsigned char*)image_data.planes[0];
107+
108+
QImage temp(bgr_img_data,
109+
image_info.width,
110+
image_info.height,
111+
QImage::Format_RGB888);
112+
113+
// Convert data from BGR (PXCImage format) to RGB (QPixmap)
114+
QPixmap pixmap = QPixmap::fromImage(temp.rgbSwapped());
115+
emit notify_image(pixmap);
116+
}
117+
else
118+
{
119+
std::cout << "!!! TODO: support other image formats besides RGB24." << std::endl;
120+
_pipeline.ReleaseFrame();
121+
return;
122+
}
123+
124+
image->ReleaseAccess(&image_data);
125+
if (sts < PXC_STATUS_NO_ERROR)
126+
{
127+
std::cout << "!!! Failed ReleaseAccess." << std::endl;
128+
_pipeline.ReleaseFrame();
129+
return;
130+
}
131+
132+
/* Detect gestures */
133+
134+
PXCGesture* gesture = _pipeline.QueryGesture();
135+
if (gesture)
136+
{
137+
// get the node data for the whole primary hand
138+
// (the one that shows up in the view first)
139+
PXCGesture::GeoNode node;
140+
sts = gesture->QueryNodeData(0, PXCGesture::GeoNode::LABEL_BODY_HAND_PRIMARY, &node);
141+
if (sts == PXC_STATUS_ITEM_UNAVAILABLE)
142+
{
143+
//std::cout << "!!! QueryNodeData: PXC_STATUS_ITEM_UNAVAILABLE" << std::endl;
144+
_pipeline.ReleaseFrame();
145+
return;
146+
}
147+
148+
//std::cout << "* Hand at " << node.positionWorld.x << "x" << node.positionWorld.y << " z = " << node.positionWorld.z << std::endl;
149+
150+
PXCGesture::Gesture gest;
151+
sts = gesture->QueryGestureData(0, PXCGesture::GeoNode::LABEL_BODY_HAND_PRIMARY, 0, &gest);
152+
if (sts == PXC_STATUS_ITEM_UNAVAILABLE)
153+
{
154+
//std::cout << "!!! QueryGestureData: PXC_STATUS_ITEM_UNAVAILABLE" << std::endl;
155+
_pipeline.ReleaseFrame();
156+
return;
157+
}
158+
159+
if (gest.active)
160+
{
161+
// how many ms has passed since last gesture detection
162+
qint64 elapsed = _elapsed_timer.elapsed();
163+
164+
switch (gest.label)
165+
{
166+
case PXCGesture::Gesture::LABEL_HAND_WAVE:
167+
case PXCGesture::Gesture::LABEL_NAV_SWIPE_LEFT:
168+
case PXCGesture::Gesture::LABEL_NAV_SWIPE_RIGHT:
169+
case PXCGesture::Gesture::LABEL_NAV_SWIPE_UP:
170+
case PXCGesture::Gesture::LABEL_NAV_SWIPE_DOWN:
171+
case PXCGesture::Gesture::LABEL_HAND_CIRCLE:
172+
default:
173+
emit notify_gesture(gest);
174+
break;
175+
176+
case PXCGesture::Gesture::LABEL_POSE_THUMB_UP:
177+
if ( (_last_gesture == PXCGesture::Gesture::LABEL_POSE_THUMB_UP && elapsed > 1000) ||
178+
(_last_gesture != PXCGesture::Gesture::LABEL_POSE_THUMB_UP) )
179+
emit notify_gesture(gest);
180+
break;
181+
182+
case PXCGesture::Gesture::LABEL_POSE_THUMB_DOWN:
183+
if ( (_last_gesture == PXCGesture::Gesture::LABEL_POSE_THUMB_DOWN && elapsed > 1000) ||
184+
(_last_gesture != PXCGesture::Gesture::LABEL_POSE_THUMB_DOWN) )
185+
emit notify_gesture(gest);
186+
break;
187+
188+
case PXCGesture::Gesture::LABEL_POSE_PEACE:
189+
if ( (_last_gesture == PXCGesture::Gesture::LABEL_POSE_PEACE && elapsed > 1000) ||
190+
(_last_gesture != PXCGesture::Gesture::LABEL_POSE_PEACE) )
191+
emit notify_gesture(gest);
192+
break;
193+
194+
case PXCGesture::Gesture::LABEL_POSE_BIG5:
195+
if ( (_last_gesture == PXCGesture::Gesture::LABEL_POSE_BIG5 && elapsed > 1000) ||
196+
(_last_gesture != PXCGesture::Gesture::LABEL_POSE_BIG5) )
197+
emit notify_gesture(gest);
198+
break;
199+
}
200+
_last_gesture = gest.label;
201+
if (elapsed > 1000)
202+
_elapsed_timer.restart();
203+
}
204+
}
205+
206+
_pipeline.ReleaseFrame();
207+
}
208+

ipcQTgesture/gesture_handler.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma once
2+
#include "util_render.h"
3+
#include "util_pipeline.h"
4+
5+
#include <QElapsedTimer>
6+
#include <QSize>
7+
#include <QObject>
8+
#include <QTimer>
9+
#include <QPixmap>
10+
11+
12+
class GestureHandler : public QObject
13+
{
14+
Q_OBJECT
15+
public:
16+
GestureHandler();
17+
~GestureHandler();
18+
19+
bool start();
20+
void stop();
21+
QSize image_size();
22+
23+
signals:
24+
void notify_gesture(PXCGesture::Gesture gesture_evt);
25+
void notify_image(QPixmap pixmap);
26+
27+
private slots:
28+
void _stream();
29+
30+
private:
31+
bool _streaming;
32+
bool _init_error;
33+
QTimer _fps_timer;
34+
UtilPipeline _pipeline;
35+
QElapsedTimer _elapsed_timer;
36+
PXCGesture::Gesture::Label _last_gesture;
37+
};

ipcQTgesture/ipcQTgesture.pro

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
QT += core gui widgets
2+
3+
SOURCES += \
4+
ipc_window.cpp \
5+
main.cpp \
6+
gesture_handler.cpp
7+
8+
HEADERS += \
9+
ipc_window.h \
10+
gesture_handler.h
11+
12+
win32 {
13+
QMAKE_CXXFLAGS_DEBUG += -Zi -MTd
14+
QMAKE_CXXFLAGS_RELEASE += -MT
15+
16+
INCLUDEPATH += "C:\\Program Files\\Intel\\PCSDK\\include" \
17+
"C:\\Program Files\\Intel\\PCSDK\\sample\\common\\include" \
18+
"C:\\Program Files\\Intel\\PCSDK\\sample\\common\\res"
19+
20+
LIBS += -L"C:\\Program Files\\Intel\\PCSDK\\lib\\Win32" \
21+
-L"C:\\Program Files\\Intel\\PCSDK\\sample\\common\\lib\\Win32\\v100"
22+
23+
CONFIG (debug, debug|release) {
24+
message("* Configuring project for Debug.")
25+
26+
LIBS += -llibpxc_d \
27+
-llibpxcutils_d
28+
29+
LIBS += "advapi32.lib" "msvcrtd.lib" "libcmtd.lib"
30+
}
31+
else {
32+
message("* Configuring project for Release.")
33+
34+
LIBS += -llibpxc \
35+
-llibpxcutils
36+
37+
LIBS += "advapi32.lib" "msvcrt.lib" "libcmt.lib"
38+
}
39+
40+
}
41+

0 commit comments

Comments
 (0)