Esempio n. 1
0
XnUserID hiKinect::getTrackedUserID(){
  XnUInt16 nUsers = g_UserGenerator.GetNumberOfUsers();
  XnUserID aUsers[nUsers];
  g_UserGenerator.GetUsers(aUsers, nUsers);
  xn::SkeletonCapability cap = g_UserGenerator.GetSkeletonCap();
  for (int i = 0; i < nUsers; ++i) {
    if (cap.IsTracking(aUsers[i])) {
      return aUsers[i];
    }
  }
  return 0;
}
Esempio n. 2
0
// ユーザー検出
void XN_CALLBACK_TYPE UserDetected(xn::UserGenerator& generator,
    XnUserID nId, void* pCookie)
{
    std::cout << "ユーザー検出:" << nId << " " << generator.GetNumberOfUsers() << "人目" << std::endl;

    XnChar* pose = (XnChar*)pCookie;
    if (pose[0] != '¥0') {
        generator.GetPoseDetectionCap().StartPoseDetection(pose, nId);
    }
    else {
        generator.GetSkeletonCap().RequestCalibration(nId, TRUE);
    }
}
Esempio n. 3
0
void XN_CALLBACK_TYPE
User_NewUser(xn::UserGenerator& generator, XnUserID nId, void* pCookie) {
  printf("New User: %d\n", nId);
  FBLOG_INFO("User_NewUser", nId);
  XnUInt16 nUsers = g_UserGenerator.GetNumberOfUsers();
  XnUserID aUsers[nUsers];
  g_UserGenerator.GetUsers(aUsers, nUsers);
  for (int i = 0; i < nUsers; ++i) {
    if (g_UserGenerator.GetSkeletonCap().IsTracking(aUsers[i])) {
      return;
    }
  }
  g_UserGenerator.GetPoseDetectionCap().StartPoseDetection(POSE_TO_USE, nId);
  (*((hiKinect *)pCookie)->callbackPtr)->InvokeAsync("", FB::variant_list_of("NEW_USER"));
}
Esempio n. 4
0
// ユーザー検出
void XN_CALLBACK_TYPE UserDetected(xn::UserGenerator& generator, XnUserID nId, void* pCookie)
{
    std::cout << "ユーザー検出:" << nId << " " << generator.GetNumberOfUsers() << "人目" << std::endl;
    
    // キャリブレーションデータをロードする
    if ( !LoadCalibration( generator ) ) {
        // ファイルからトラッキングできなければ、ポーズからキャリブレーションを行う
        XnChar* pose = (XnChar*)pCookie;
        if (pose[0] != '¥0') {
            generator.GetPoseDetectionCap().StartPoseDetection(pose, nId);
        }
        else {
            generator.GetSkeletonCap().RequestCalibration(nId, TRUE);
        }
    }
}
Esempio n. 5
0
reader_result kinect_reader2::get_next() {
	XnUserID aUsers[15];
	XnUInt16 nUsers = 15;
	XnSkeletonJointPosition joint;

	while(true) {
		// Read next available data
		nRetVal = g_Context.WaitOneUpdateAll(g_DepthGenerator);
		if(nRetVal != XN_STATUS_OK) {
			printf("Failed updating data: %s\n", xnGetStatusString(nRetVal));
			continue;
		}

		if(g_UserGenerator.GetNumberOfUsers() > 0) {

			g_UserGenerator.GetUsers(aUsers, nUsers);
			for(int i=0; i< nUsers; i++)
			{
				if(g_UserGenerator.GetSkeletonCap().IsTracking(aUsers[i]))
				{
					reader_result new_tuple;

					// player
					new_tuple.push_back(boost::any((int)aUsers[i]));

					// 1 = XN_SKEL_HEAD, ..., 24 = XN_SKEL_RIGHT_FOOD
					for(short j = 1; j <= 24; j++) {
						g_UserGenerator.GetSkeletonCap().GetSkeletonJointPosition(aUsers[i], (XnSkeletonJoint)j, joint);
						new_tuple.push_back(boost::any(boost::lexical_cast<std::string>((float)joint.position.X)));
						new_tuple.push_back(boost::any(boost::lexical_cast<std::string>((float)joint.position.Y)));
						new_tuple.push_back(boost::any(boost::lexical_cast<std::string>((float)joint.position.Z)));
						new_tuple.push_back(boost::any(boost::lexical_cast<std::string>((float)joint.fConfidence)));
					}

					return new_tuple;
				}
			}
		}
	}
}
Esempio n. 6
0
//----------------------------------------------------
// ユーザー検出
//----------------------------------------------------
void XN_CALLBACK_TYPE UserDetected(xn::UserGenerator& generator, XnUserID nId, void* pCookie){
	cout << "ユーザー検出:" << nId << " " << generator.GetNumberOfUsers() << "人目" << endl;
}
int main() {
	printf("main() START\n");
	signal(SIGINT, onSignalReceived); // hit CTRL-C keys in terminal (2)
	signal(SIGTERM, onSignalReceived); // hit stop button in eclipse CDT (15)

	mapMode.nXRes = XN_VGA_X_RES;
	mapMode.nYRes = XN_VGA_Y_RES;
	mapMode.nFPS = 30;

	CHECK_RC(ctx.Init(), "init");
	CHECK_RC(depthGenerator.Create(ctx), "create depth");
	depthGenerator.SetMapOutputMode(mapMode);

	XnStatus userAvailable = ctx.FindExistingNode(XN_NODE_TYPE_USER, userGenerator);
	if(userAvailable != XN_STATUS_OK) {
		CHECK_RC(userGenerator.Create(ctx), "create user");
	}

	XnCallbackHandle hUserCallbacks, hCalibrationCallbacks, hPoseCallbacks;
	xn::SkeletonCapability skel = userGenerator.GetSkeletonCap();
	CHECK_RC(userGenerator.RegisterUserCallbacks(onUserNew, onUserLost, NULL, hUserCallbacks), "register user");
	CHECK_RC(skel.RegisterCalibrationCallbacks(onCalibrationStart, onCalibrationEnd, NULL, hCalibrationCallbacks), "register calib");
	CHECK_RC(userGenerator.GetPoseDetectionCap().RegisterToPoseCallbacks(onPoseDetected, NULL, NULL, hPoseCallbacks), "register pose");

	XnChar poseName[20] = "";
	CHECK_RC(skel.GetCalibrationPose(poseName), "get posename");
	printf("poseName: %s\n", poseName);
	CHECK_RC(skel.SetSkeletonProfile(XN_SKEL_PROFILE_ALL), "set skel profile");
	CHECK_RC(skel.SetSmoothing(0.8), "set smoothing");
//	xnSetMirror(depth, !mirrorMode);

	CHECK_RC(ctx.StartGeneratingAll(), "start generating");

	printf("waitAnyUpdateAll ...\n");
	while(!shouldTerminate) {
		ctx.WaitAnyUpdateAll();
//		depthGenerator.GetMetaData(tempDepthMetaData);

		const XnUInt16 userCount = userGenerator.GetNumberOfUsers();
//		printf("userCount: %i\n", userCount);
		XnUserID aUsers[userCount];
		XnUInt16 nUsers = userCount;
		userGenerator.GetUsers(aUsers, nUsers);
		for (int i = 0; i < nUsers; ++i) {
			XnUserID currentUserId = aUsers[i];
			if (skel.IsTracking(aUsers[i])) {
				XnSkeletonJointPosition joint;
				skel.GetSkeletonJointPosition(currentUserId, XN_SKEL_HEAD, joint);
				XnFloat x = joint.position.X;
				XnFloat y = joint.position.Y;
				XnFloat z = joint.position.Z;
				printf("joint position: %.2f x %.2f x %.2f\n", x, y, z);
				printf("joint.fConfidence: %.2f\n", joint.fConfidence);
			}
		}
	}
	printf("STOP\n");
	CHECK_RC(ctx.StopGeneratingAll(), "stop generating");
	ctx.Shutdown();

	printf("main() END\n");
}