这是第二个范例,小斤将介绍如何使用OpenNI让Kinect识别出手势,并显示输出。目前版本的OpenNI支持四种手势:RaiseHand, Wave, Click和MovingHand,分别代表手的“举起”,“挥动”,“前推”和“移动”四种动作。值得一提的是,当前微软官方的Kinect SDK还不支持手势识别,也可以说是使用OpenNI的好处之一吧。
有了手势识别后,其实可以利用Kinect做一些实际的东东,比如利用鼠标键盘控制一些应用程序等等。
有了手势识别后,其实可以利用Kinect做一些实际的东东,比如利用鼠标键盘控制一些应用程序等等。
闲话不说了,速度搞起。代码一部分参考了Heresy童鞋的文章,手势部分写得很完备了,在巨人的肩膀上,小斤使用OpenCV进行显示,红色点表示手的位置轨迹,蓝色实心圈表示前推的位置,黄色直线表示手挥动的轨迹(从起点到终点)。
#include <stdlib.h>
#include <iostream>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <XnCppWrapper.h>
using namespace std;
using namespace cv;
// output for XnPoint3D
ostream& operator<<( ostream& out, const XnPoint3D& rPoint )
{
out << "(" << rPoint.X << "," << rPoint.Y << "," << rPoint.Z << ")";
return out;
}
//【4】
// callback function for gesture recognized
void XN_CALLBACK_TYPE gestureRecog( xn::GestureGenerator &generator,
const XnChar *strGesture,
const XnPoint3D *pIDPosition,
const XnPoint3D *pEndPosition,
void *pCookie )
{
cout << strGesture<<" from "<<*pIDPosition<<" to