OPENNI中usergenerator的使用
来源:互联网 发布:全国违章查询软件 编辑:程序博客网 时间:2024/05/20 07:33
#include <stdlib.h>#include <iostream>#include <string>#include <XnCppWrapper.h>#include <opencv2/opencv.hpp>#include <opencv2/highgui/highgui.hpp>#include <opencv2/core/core.hpp>using namespace std;using namespace xn;using namespace cv;void XN_CALLBACK_TYPE LostUser(UserGenerator& generator,XnUserID user,void* pCookie);void XN_CALLBACK_TYPE NewUser(UserGenerator& generator,XnUserID user,void* pCookie);void XN_CALLBACK_TYPE poseDetected(xn::PoseDetectionCapability& poseDetection,const XnChar* strPose,XnUserID user, void *pCookie);void XN_CALLBACK_TYPE CalibrationStart(xn::SkeletonCapability& skeleton,XnUserID user,void* pCookie);void XN_CALLBACK_TYPE CalibrationEnd(xn::SkeletonCapability& skeleton,XnUserID user,XnBool bSuccess,void* pCookie);bool Calibflage;int startSkelPoints[14]={1,2,6,6,12,17,6,7,12,13,17,18,21,22};int endSkelPoints[14]={2,3,12,21,17,21,7,9,13,15,18,20,22,24};void CheckOpenNIError(XnStatus eResult,string sStatus){if(eResult != XN_STATUS_OK)cout << sStatus << "Error: " << xnGetStatusString(eResult) << endl;//P53}int main(){XnStatus eResult = XN_STATUS_OK;namedWindow("image");namedWindow("clone");DepthMetaData mDepth;ImageMetaData mImage;Context mContext;eResult = mContext.Init();CheckOpenNIError(eResult,"Initialize context");UserGenerator xUserGenerator;xUserGenerator.Create(mContext);ImageGenerator mImageGenerator;mImageGenerator.Create(mContext);DepthGenerator mDepthGenerator;mDepthGenerator.Create(mContext);XnMapOutputMode mapMode;mapMode.nXRes=640;mapMode.nYRes=480;mapMode.nFPS=30;mDepthGenerator.SetMapOutputMode(mapMode);mImageGenerator.SetMapOutputMode(mapMode);mDepthGenerator.GetMirrorCap().SetMirror(true);mImageGenerator.GetMirrorCap().SetMirror(true);mDepthGenerator.GetAlternativeViewPointCap().SetViewPoint(mImageGenerator);XnCallbackHandle hUseCB;//检测用户xUserGenerator.RegisterUserCallbacks(NewUser,LostUser,NULL,hUseCB);XnCallbackHandle hposeCB;//检测姿势xUserGenerator.GetPoseDetectionCap().RegisterToPoseCallbacks(poseDetected,NULL,&xUserGenerator,hposeCB);XnCallbackHandle hCalibCB;//骨骼标定xn::SkeletonCapability mSC=NULL;mSC=xUserGenerator.GetSkeletonCap();mSC.SetSkeletonProfile(XN_SKEL_PROFILE_ALL);mSC.RegisterCalibrationCallbacks(CalibrationStart,CalibrationEnd,&xUserGenerator,hCalibCB);mContext.StartGeneratingAll();while (1){mContext.WaitAndUpdateAll();mImageGenerator.GetMetaData(mImage);Mat cvRGBImage(mImage.FullYRes(),mImage.FullXRes(),CV_8UC3,(char*) mImage.Data());Mat cvBGRImage;cvtColor(cvRGBImage,cvBGRImage,CV_RGB2BGR);Mat clImage=cvBGRImage.clone();XnUInt16 nUsers=xUserGenerator.GetNumberOfUsers();if (nUsers>0&&Calibflage){XnUserID* aUserID=new XnUserID[nUsers];xUserGenerator.GetUsers(aUserID,nUsers);XnPoint3D* UserCoM=new XnPoint3D[nUsers];XnPoint3D* projectpoint=new XnPoint3D[nUsers];xn::SceneMetaData* SceneMD=new xn::SceneMetaData[nUsers];for (int i=0;i<nUsers;i++){xUserGenerator.GetCoM(aUserID[i],UserCoM[i]);mDepthGenerator.ConvertRealWorldToProjective(1,UserCoM,projectpoint);if( xUserGenerator.GetSkeletonCap().IsTracking( aUserID[i] ) ){XnPoint3D skelPointsIn[24],skelPointsOut[24];XnSkeletonJointPosition mJointTran;for(int iter=0;iter<24;iter++){//XnSkeletonJoint from 1 to 24xUserGenerator.GetSkeletonCap().GetSkeletonJointPosition(aUserID[i],XnSkeletonJoint(iter+1),mJointTran);skelPointsIn[iter]=mJointTran.position;}mDepthGenerator.ConvertRealWorldToProjective(24,skelPointsIn,skelPointsOut);for(int d=0;d<24;d++){Point startpoint=Point(skelPointsOut[d].X,skelPointsOut[d].Y);circle(cvBGRImage,startpoint,3,CV_RGB(0,0,255),12);}xUserGenerator.GetUserPixels(aUserID[i],SceneMD[i]);for (int j=0;j<clImage.cols;j++){for (int k=0;k<clImage.rows;k++){if (SceneMD[i](j,k)==0){for(int n=0;n<3;n++)clImage.at<uchar>(k,j*3+n)=0;}}}}circle(cvBGRImage,Point(projectpoint[i].X,projectpoint[i].Y),10,Scalar(255,255,255),10);}delete[] projectpoint;delete[] UserCoM;delete[] aUserID;}imshow("image",cvBGRImage);imshow("clone",clImage);waitKey(30);}mContext.Shutdown();return 0;}void XN_CALLBACK_TYPE LostUser(UserGenerator& generator,XnUserID user,void* pCookie){printf("Lost User:%d\n",user);}void XN_CALLBACK_TYPE NewUser(UserGenerator& generator,XnUserID user,void* pCookie){printf("New User identified:%d\n",user);generator.GetPoseDetectionCap().StartPoseDetection("Psi",user);}void XN_CALLBACK_TYPE poseDetected(xn::PoseDetectionCapability& poseDetection,const XnChar* strPose,XnUserID user, void *pCookie){printf("pose %s,detected for user %d",strPose,user);((xn::UserGenerator*)pCookie)->GetSkeletonCap().RequestCalibration(user,FALSE);poseDetection.StopPoseDetection( user );}void XN_CALLBACK_TYPE CalibrationStart(xn::SkeletonCapability& skeleton,XnUserID user,void* pCookie){printf("Calibration start for user:%d\n",user);}void XN_CALLBACK_TYPE CalibrationEnd(xn::SkeletonCapability& skeleton,XnUserID user,XnBool bSuccess,void* pCookie){printf("Calibration complete: user");if (bSuccess){printf("success");Calibflage=true;skeleton.StartTracking(user);}else{printf("Failure\n");((xn::UserGenerator*)pCookie)->GetPoseDetectionCap().StartPoseDetection("Psi",user);}}利用GetuserPIxels去抠人像,效果一般,还需要进行进一步处理。
0 0
- OPENNI中usergenerator的使用
- 关于UserGenerator的函数getUserPixels()
- 在Mac中使用OpenNI
- kinect开发的openni使用
- 使用opencv显示openni获取的图像
- 使用OpenNI 控制Kinect 的马达
- Kinect+OpenNI学习笔记之5(使用OpenNI自带的类进行简单手势识别)
- Kinect+OpenNI+OpenCV使用
- xbox360 +openni使用问题
- Kinect开发中OpenNI的配置与安装
- OPenNI的下载
- OpenNI
- Kinect+OpenNI+PCL使用初级
- window7+openni的kinect配置
- OpenNI的安装与配置
- ros&kinect的openni驱动
- OpenCV使用Kinect和其他OpenNI兼容的深度传感器(opencv_user.pdf 3.1章)
- VisualStudio2012 & OpenCV & OpenNi编写运行C++代码使用配置的详细说明
- Heap & Priority Queue
- android 常用效果
- 在windows下安装配置mongodb
- Android6.0以上,动态权限申请
- 正则表达式-1 (字符串匹配)
- OPENNI中usergenerator的使用
- 373. Find K Pairs with Smallest Sums
- 用C#实现凯撒密码算法
- HID描述符
- Python基础学习--第十一篇(模块)
- 异常处理 UnsupportedMethodException
- Python 之真假“美猴王”
- iOS升级到10,打包遇到了一些问题
- 选择性排序