locked
Skeleton Frame and Closing Video Stream Issue RRS feed

  • Question

  • Hi,

    My game uses skeleton frame for motion detection logics.

    It is divided into 2 phases:

    1. Detection

    - Displays depth video as background

    - Detects who are player 1 and player 2 by standing position.

    2. Game-play

    - Use skeleton frame to analyse user motion

    - No depth video.

     

    When switching from phase 1 to 2, I'd like to stop the depth video stream processing. I tried several ways but all have problems:

    - Once a video stream is enabled, I cannot disable it.

    - If I ignore the video stream by not calling "NuiImageStreamGetNextFrame", I can never get the skeleton frame event from "WaitForMultipleObjects". There is no such problem if no video stream is enabled. (We can reproduce this problem in SkeletalViewer example by commenting line 275  pthis->Nui_GotDepthAlert();)

    - If I shut down Nui and reinitialize without video stream, I will lose the player ID and phase 1 will become meaningless.

     

    Any idea? Thanks.

    Man


    • Edited by mancheung Wednesday, September 7, 2011 11:13 AM
    Wednesday, September 7, 2011 9:25 AM

Answers

  • Actually, I just found an even better workaround that is the simplest and probably result in the least code changes on your part:

    4) Replace the call to pthis->Nui_GotDepthAlert(); with

    ResetEvent(pthis->m_hNextDepthFrameEvent);

    Hope this helps!
    Eddy


    I'm here to help
    Wednesday, September 7, 2011 9:17 PM

All replies

  • Even when you don't ask for depth frames, the Kinect Runtime is retrieving and processing depth from Kinect device in order to produce skeleton data, so I'm guessing that the main impetus you have for disabling this is to avoid additional memory from being allocated by your application, via calls to NuiImageStreamGetNextFrame and NuiImageStreamReleaseFrame, correct?

    I can confirm that I see the same problem you mention regarding that if you do have depth events enabled and you never call "NuiImageStreamGetNextFrame", the runtime seems to get stuck triggering depth event, never signaling any other event, so I'll make sure we're tracking the issue. Thanks for the report!

    I can think of 3 possible workarounds for your problem:

    1) When you're on "stage 2", just make sure that you call NuiImageStreamGetNextFrame and NuiImageStreamReleaseFrame without any other processing when you receive a depth frame ready event. Not ideal as far as resource consumption, but hopefully it shouldn't unacceptably increase your application's memory footprint unless you're running on a system with limited memory capacity.

    2) Change your code to retrieve frames in a "polling model", instead of an "event model", as described in page 19 of programming guide (http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/docs/ProgrammingGuide_KinectSDK.pdf). Basically you would not create m_hNextDepthFrameEvent neither m_hNextSkeletonEvent, and you would pass NULL to both first parameter in NuiSkeletonTrackingEnable and fifth parameter of NuiImageStreamOpen. Also, to minimize code changes you could keep Nui_ProcessThread, but call NuiImageStreamGetNextFrame and NuiSkeletonGetNextFrame with a wait time of 20-30 milliseconds. Since frame wouldn't be guaranteed to be delivered in this case every time, you'd have to check return value for E_NUI_FRAME_NO_DATA.

    3) If the main thing you need depth stream for is to detect position of players 1 and 2, and from then on just use skeletons and not even display depth stream anymore, then you could completely get rid of stage 1 and just determine who is player 1 and who is player 2 from skeleton positions.

    Hope some of this helps!
    Eddy


    I'm here to help
    Wednesday, September 7, 2011 9:09 PM
  • Actually, I just found an even better workaround that is the simplest and probably result in the least code changes on your part:

    4) Replace the call to pthis->Nui_GotDepthAlert(); with

    ResetEvent(pthis->m_hNextDepthFrameEvent);

    Hope this helps!
    Eddy


    I'm here to help
    Wednesday, September 7, 2011 9:17 PM
  • Solution 4 works! Thank you Eddy.

    Man

    Thursday, September 8, 2011 3:45 AM