資源簡介
因為OpenNI可以獲取到kinect的深度信息,而深度信息在手勢識別中有很大用處,因此本文就來使用OpenNI自帶的類來做簡單的手勢識別。識別的動作為4種,揮手,手移動,舉手,往前推手。通過后面的實驗可以發(fā)現(xiàn),其實提供的類的效果非常不好。
開發(fā)環(huán)境:QtCreator2.5.1+OpenNI1.5.4.0+Qt4.8.2+OpenCV2.4.2

代碼片段和文件信息
#include?
#include?
#include?
using?namespace?xn;
using?namespace?std;
class?COpenNI
{
public:
????~COpenNI()?{
????????context.Release();//釋放空間
????}
????bool?Initial()?{
????????//初始化
????????status?=?context.Init();
????????if(CheckError(“Context?initial?failed!“))?{
????????????return?false;
????????}
????????context.SetGlobalMirror(true);//設(shè)置鏡像
????????//產(chǎn)生圖片node
????????status?=?image_generator.Create(context);
????????if(CheckError(“Create?image?generator??error!“))?{
????????????return?false;
????????}
????????//產(chǎn)生深度node
????????status?=?depth_generator.Create(context);
????????if(CheckError(“Create?depth?generator??error!“))?{
????????????return?false;
????????}
????????//視角校正
????????status?=?depth_generator.GetAlternativeViewPointCap().SetViewPoint(image_generator);
????????if(CheckError(“Can‘t?set?the?alternative?view?point?on?depth?generator!“))?{
????????????return?false;
????????}
????????status?=?gesture_generator.Create(context);
????????if(CheckError(“Create?gesture?generator?error!“))?{
????????????return?false;
????????}
????????/*添加手勢識別的種類*/
????????gesture_generator.AddGesture(“Wave“?NULL);
????????gesture_generator.AddGesture(“click“?NULL);
????????gesture_generator.AddGesture(“RaiseHand“?NULL);
????????gesture_generator.AddGesture(“MovingHand“?NULL);
????????return?true;
????}
????bool?Start()?{
????????status?=?context.StartGeneratingAll();
????????if(CheckError(“Start?generating?error!“))?{
????????????return?false;
????????}
????????return?true;
????}
????bool?UpdateData()?{
????????status?=?context.WaitNoneUpdateAll();
????????if(CheckError(“Update?date?error!“))?{
????????????return?false;
????????}
????????//獲取數(shù)據(jù)
????????image_generator.GetmetaData(image_metadata);
????????depth_generator.GetmetaData(depth_metadata);
????????return?true;
????}
public:
????DepthmetaData?depth_metadata;
????ImagemetaData?image_metadata;
????GestureGenerator?gesture_generator;//外部要對其進行回調(diào)函數(shù)的設(shè)置,因此將它設(shè)為public類型
private:
????//該函數(shù)返回真代表出現(xiàn)了錯誤,返回假代表正確
????bool?CheckError(const?char*?error)?{
????????if(status?!=?XN_STATUS_OK?)?{
????????????QMessageBox::critical(NULL?error?xnGetStatusString(status));
????????????cerr?<????????????return?true;
????????}
????????return?false;
????}
private:
????XnStatus????status;
????Context?????context;
????DepthGenerator??depth_generator;
????ImageGenerator??image_generator;
};
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????351744??2012-10-02?08:41??Kinect+OpenNI學習筆記之5(使用OpenNI自帶的類進行簡單手勢識別).pdf
?????文件???????2640??2012-10-01?22:28??hand_detect\copenni.cpp
?????文件??????62464??2012-10-02?00:33??hand_detect\debug\hand_detect.exe
?????文件?????526156??2012-10-02?00:33??hand_detect\debug\hand_detect.ilk
?????文件????????638??2012-10-02?00:33??hand_detect\debug\hand_detect.intermediate.manifest
?????文件????2550784??2012-10-02?00:33??hand_detect\debug\hand_detect.pdb
?????文件?????310706??2012-10-02?00:33??hand_detect\debug\main.obj
?????文件????????992??2012-10-01?22:31??hand_detect\hand_detect.pro
?????文件??????17553??2012-10-02?08:41??hand_detect\hand_detect.pro.user
?????文件???????2548??2012-10-02?00:33??hand_detect\main.cpp
?????文件???????7059??2012-10-01?22:31??hand_detect\Makefile
?????文件???????6176??2012-10-01?22:31??hand_detect\Makefile.Debug
?????文件???????6166??2012-10-01?22:31??hand_detect\Makefile.Release
?????文件????2174976??2012-10-02?00:33??hand_detect\vc100.pdb
?????目錄??????????0??2012-10-02?08:42??hand_detect\debug
?????目錄??????????0??2012-10-02?08:42??hand_detect\release
?????目錄??????????0??2012-10-02?08:42??hand_detect
-----------?---------??----------?-----??----
??????????????6020602????????????????????17
- 上一篇:Windows 1.02
- 下一篇:多尺度hessian濾波器圖像增強
評論
共有 條評論