none
My kinect don't detect my skeleton

    Question

  • I open the cpp sample of SkeletalViewer and i comment main function from SkeletalViewer.cpp and my new main function is:

     

    void main(){
    	//+-------------+
    	//| Kinect Init |
    	//+-------------+
    	// Clean state the class
    	g_CSkeletalViewerApp.Nui_Zero();
    
    	// Bind application window handle
    	//g_CSkeletalViewerApp.m_hWnd=hWnd;
    
    	// Initialize and start NUI processing
    	g_CSkeletalViewerApp.Nui_Init();
    	while (true)
    	{
    		g_CSkeletalViewerApp.Nui_GetEvent();
    	}
    
    	
    }
    


    I comment from Nui_init() some line .The new Nui_init() code is:

    HRESULT CSkeletalViewerApp::Nui_Init()
    {
      HRESULT        hr;
      RECT        rc;
    
      m_hNextDepthFrameEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
      m_hNextVideoFrameEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
      m_hNextSkeletonEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
    
      GetWindowRect(GetDlgItem( m_hWnd, IDC_SKELETALVIEW ), &rc );
      int width = rc.right - rc.left;
      int height = rc.bottom - rc.top;
      HDC hdc = GetDC(GetDlgItem( m_hWnd, IDC_SKELETALVIEW));
      m_SkeletonBMP = CreateCompatibleBitmap( hdc, width, height );
      m_SkeletonDC = CreateCompatibleDC( hdc );
      ::ReleaseDC(GetDlgItem(m_hWnd,IDC_SKELETALVIEW), hdc );
      m_SkeletonOldObj = SelectObject( m_SkeletonDC, m_SkeletonBMP );
    
    //Foloseste direct3D ca sa afiseze pe ecran.NU ma intereseaza
    	/*  hr = m_DrawDepth.CreateDevice( GetDlgItem( m_hWnd, IDC_DEPTHVIEWER ) );
      if( FAILED( hr ) )
      {
        MessageBoxResource( m_hWnd,IDS_ERROR_D3DCREATE,MB_OK | MB_ICONHAND);
        return hr;
      } 
    
      hr = m_DrawDepth.SetVideoType( 320, 240, 320 * 4 );
      if( FAILED( hr ) )
      {
        MessageBoxResource( m_hWnd,IDS_ERROR_D3DVIDEOTYPE,MB_OK | MB_ICONHAND);
        return hr;
      }
    
      hr = m_DrawVideo.CreateDevice( GetDlgItem( m_hWnd, IDC_VIDEOVIEW ) );
      if( FAILED( hr ) )
      {
        MessageBoxResource( m_hWnd,IDS_ERROR_D3DCREATE,MB_OK | MB_ICONHAND);
        return hr;
      }
    
      hr = m_DrawVideo.SetVideoType( 640, 480, 640 * 4 );
      if( FAILED( hr ) )
      {
        MessageBoxResource( m_hWnd,IDS_ERROR_D3DVIDEOTYPE,MB_OK | MB_ICONHAND);
        return hr;
      }
    */  
      hr = NuiInitialize( 
        NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX | NUI_INITIALIZE_FLAG_USES_SKELETON | NUI_INITIALIZE_FLAG_USES_COLOR );
      if( FAILED( hr ) )
      {
        MessageBoxResource(m_hWnd,IDS_ERROR_NUIINIT,MB_OK | MB_ICONHAND);
        return hr;
      }
    
      hr = NuiSkeletonTrackingEnable( m_hNextSkeletonEvent, 0 );
      if( FAILED( hr ) )
      {
        MessageBoxResource(m_hWnd,IDS_ERROR_SKELETONTRACKING,MB_OK | MB_ICONHAND);
        return hr;
      }
    
      /* hr = NuiImageStreamOpen(
        NUI_IMAGE_TYPE_COLOR,
        NUI_IMAGE_RESOLUTION_640x480,
        0,
        2,
        m_hNextVideoFrameEvent,
        &m_pVideoStreamHandle );
      if( FAILED( hr ) )
      {
        MessageBoxResource(m_hWnd,IDS_ERROR_VIDEOSTREAM,MB_OK | MB_ICONHAND);
        return hr;
      }*/
    
      hr = NuiImageStreamOpen(
        NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX,
        NUI_IMAGE_RESOLUTION_320x240,
        0,
        2,
        m_hNextDepthFrameEvent,
        &m_pDepthStreamHandle );
      if( FAILED( hr ) )
      {
        MessageBoxResource(m_hWnd,IDS_ERROR_DEPTHSTREAM,MB_OK | MB_ICONHAND);
        return hr;
      }
    
      // Start the Nui processing thread
      m_hEvNuiProcessStop=CreateEvent(NULL,FALSE,FALSE,NULL);
      m_hThNuiProcess=CreateThread(NULL,0,Nui_ProcessThread,this,0,NULL);
    
      return hr;
    }
    

    The code of Nui_GetEvent() is :

     

    int CSkeletalViewerApp::Nui_GetEvent( ) {
    	
    	NUI_SKELETON_FRAME SkeletonFrame;
    
      HRESULT hr = NuiSkeletonGetNextFrame( 0, &SkeletonFrame );
    	
      bool bFoundSkeleton = true;
      for( int i = 0 ; i < NUI_SKELETON_COUNT ; i++ )
      {
    		if( SkeletonFrame.SkeletonData[i].eTrackingState == NUI_SKELETON_TRACKED )
        {
    			bFoundSkeleton = false;
        }
      }
    
      // no skeletons!
      //
      if( bFoundSkeleton )
      {
    		printf("No skeletons\n"); 
    		return (0);
      }
    
      // smooth out the skeleton data
      NuiTransformSmooth(&SkeletonFrame,NULL);
    
      // we found a skeleton, re-start the timer
      m_bScreenBlanked = false;
      m_LastSkeletonFoundTime = -1;
    
    	//View left hand and right hand coordonates
    		//Left hand
    	float hand_l_x=SkeletonFrame.SkeletonData[1].SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT].x;
    	float hand_l_y=SkeletonFrame.SkeletonData[1].SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT].y;
    	float hand_l_z=SkeletonFrame.SkeletonData[1].SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT].z;
    		//right hand
    	float hand_r_x=SkeletonFrame.SkeletonData[1].SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT].x;
    	float hand_r_y=SkeletonFrame.SkeletonData[1].SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT].y;
    	float hand_r_z=SkeletonFrame.SkeletonData[1].SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT].z;
    	if (hand_l_x!=0 || hand_l_y!=0 || hand_l_z!=0 || hand_r_x!=0 || hand_r_y!=0 || hand_r_z!=0) 
    	{
    		printf("HandLeft X=%4.2f	",hand_l_x,"HandLeft Y=%4.2f	",hand_l_y,"HandLeft Z=%4.2f	\r\n",hand_l_z);
    		printf("HandRight X=%4.2f	",hand_r_x,"HandRight Y=%4.2f	",hand_r_y,"HandRight Z=%4.2f	\r\n",hand_r_z);	
    	}
    	//Tin minte ultimul frame
    	//Last_SkeletonFrame=SkeletonFrame;
    	return(0);
    }
    

    Why i recive "No skeletons" from Nui_GetEvent() message all the time.What's wrong?

     

     

    Monday, June 27, 2011 1:25 PM

Answers

  • So, I see that you're using a skeleton frame polling method instead of waiting for skeleton ready event to be fired. So, it is expected that most of the time you wouldn't have any skeletons tracked. If you used model of waiting for event to be fired, as in sample, then you will be notified when pipeline detected a skeleton, but if you just call NuiSkeletonGetNextFrame it is expected that most of the time there will be no skeleton tracked.

    If you're saying that you never see skeleton being tracked at all, next question is, does your entire body fit within camera frame? SDK only supports full body skeleton tracking.

    Does the SkeletalViewer sample work for you as expected? If so, we can probably narrow down the problem by seeing what's different. If it doesn't work for you, then we can try to get that working first.

    Hope this helps!
    Eddy


    I'm here to help
    Wednesday, June 29, 2011 2:14 AM

All replies

  • In this code, you've got the test backward:

      bool bFoundSkeleton = true;
      for( int i = 0 ; i < NUI_SKELETON_COUNT ; i++ )
      {
        if( SkeletonFrame.SkeletonData[i].eTrackingState == NUI_SKELETON_TRACKED )
          {bFoundSkeleton = false;}
      }

      // no skeletons!
      //
      if( bFoundSkeleton )

    You're setting bFoundSkeleton to false when you find a tracked skeleton.

    Instead, set bFoundSkeleton to false before the loop, and then within the loop, set it to true when you find a skeleton with tracking state NUI_AKELETON_TRACKED.

    Monday, June 27, 2011 8:48 PM
  • So, I see that you're using a skeleton frame polling method instead of waiting for skeleton ready event to be fired. So, it is expected that most of the time you wouldn't have any skeletons tracked. If you used model of waiting for event to be fired, as in sample, then you will be notified when pipeline detected a skeleton, but if you just call NuiSkeletonGetNextFrame it is expected that most of the time there will be no skeleton tracked.

    If you're saying that you never see skeleton being tracked at all, next question is, does your entire body fit within camera frame? SDK only supports full body skeleton tracking.

    Does the SkeletalViewer sample work for you as expected? If so, we can probably narrow down the problem by seeing what's different. If it doesn't work for you, then we can try to get that working first.

    Hope this helps!
    Eddy


    I'm here to help
    Wednesday, June 29, 2011 2:14 AM