how to save real time skeleton data in C++ RRS feed

  • Question

  • Hi guys,
    I'm totally new in C++ and kinect programming. But i need to record the real time skeleton data into a txt/xsl file. Can you guys teach me how to do it? I'm using Prime Sense stickfigure sample. I have tried the ofstream method,but i think it only record one point of time. Is there anything missed for me to record real time data?
    #include <iostream>   using std::cerr;
    using std::endl;
    #include <fstream>
    using std::ofstream;
    #include <cstdlib>   
    //in void DrawSingleUser
    XnSkeletonJointPosition head;
    g_UserGenerator.GetSkeletonCap().GetSkeletonJointPosition(user, XN_SKEL_HEAD, head);
    ofstream outdata; // outdata is like cin"skeleton data-2.xls"); // opens the file
    outdata <<head.position.X;
    outdata << "\t" << head.position.Y;
    outdata  << "\t" << head.position.Z;
     And i also tried the other method, i tried to change the part used for record depthdata,but also not successed.
    void StartCapture()
    	char recordFile[256] = {0};
    	time_t rawtime;
    	struct tm *timeinfo;
    	timeinfo = localtime(&rawtime);
    	XnUInt32 size;
    	xnOSStrFormat(recordFile, sizeof(recordFile)-1, &size,
    		timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
    	if (g_pRecorder != NULL)
    	XnStatus nRetVal = XN_STATUS_OK;
    	g_pRecorder = new xn::Recorder;
    	nRetVal = g_Context.CreateAnyProductionTree(XN_NODE_TYPE_RECORDER, NULL, *g_pRecorder);
    	START_CAPTURE_CHECK_RC(nRetVal, "Create recorder");
    	nRetVal = g_pRecorder->SetDestination(XN_RECORD_MEDIUM_FILE, recordFile);
    	START_CAPTURE_CHECK_RC(nRetVal, "set destination");
    	nRetVal = g_pRecorder->AddNodeToRecording(g_UserGenerator, XN_CODEC_NULL);
    	START_CAPTURE_CHECK_RC(nRetVal, "add node");
    	g_bRecord = true;

    Anyone can help me correct the code?
    Thursday, January 12, 2012 1:51 AM

All replies

  • #include "NuiApi.h"
    //in main
    //Then, start a timer of sorts that times out every 100ms for example, and calls a separate function
    //In that function:
    NUI_SKELETON_FRAME skeletonFrame;
    NuiSkeletonGetNextFrame (0, &skeletonFrame);
    for (int i = 0; i < NUI_SKELETON_COUNT; i++)
        if (skeletonFrame.SkeletonData[i].eTrackingState == NUI_SKELETON_TRACKED)
                float rightHandXval = skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT].x;
                //At this point, do whatever you want with that x val. You can access x, y and z co-ords for hands, feet, head, knees, etc in this manner.
    I knocked this together, something like this should give you all the information you need. Of course, it doesn't compile... But it is close to working code, and just requires you to find a way of creating a timer that can call that function. Of course, this is poll-based, not event-driven. However, it is very useful for my needs, as I can then modify the sample rate. I imagine there are better ways of doing this, of course.
    • Proposed as answer by Emile Victor Thursday, January 12, 2012 11:04 PM
    Thursday, January 12, 2012 6:06 AM
  • Hi emile,thank you for your help. may i check with you the code you provide should combine with which record method? Cause i need save all skeleton data into a txt file, sorry for ask so many questions. i really new to skeleton programming.

    Thursday, January 12, 2012 7:53 AM
  • I'm sorry, that's out of the scope of what I currently know. :( I would suggest asking on #C++ at
    Thursday, January 12, 2012 11:05 PM