none
only assign index 0 to multiple Kinects in mutiple processes(applications) on the same computer? RRS feed

  • Question

  • Here's a question about using NuiCreateSensorByIndex() API and create a runtime for a particular sensor, when I run multiple (3) applications with 1 Kinect for each of the application:

    if want to get skeleton tracking on each Kinect, then I need to assign index 0 to all the 3 Kinects, as the Kinect sdk can only do skeleton tracking with the Kinect at index 0.

    Then, how can that happen? Is it right that I just do the following in each application?

        INuiInstance* myInstance;
        MSR_NuiCreateInstanceByIndex(0,&myInstance);

    If so, will the 2nd and 3rd application I run automatically detect the Kinect that is not being used, and assign that Kinect to index 0 in it's own process? (basically, the question is: how to point a particular Kinect to a particular application)

    Thank you very much ahead. I will wait for any suggestions/guess.

    Lining YAO

    Monday, March 5, 2012 3:43 PM

Answers

  • From your sample code, it appears you may be using the Beta SDK. You probably want to upgrade to the V1.0 release.

    It is not true that skeleton tracking may be used only on the Kinect sensor at index 0; you can use it on any one connected sensor per process.

    Skeleton tracking is available on the first sensor for which you call NuiInitialize with either NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX or NUI_INITIALIZE_FLAG_USES_SKELETON. After initializing a sensor with either (or both) of those flags, all attempts to do the same with any other sensor will return  E_NUI_SKELETAL_ENGINE_BUSY.

    John
    K4W Dev

    Tuesday, March 6, 2012 10:05 PM

All replies

  • From your sample code, it appears you may be using the Beta SDK. You probably want to upgrade to the V1.0 release.

    It is not true that skeleton tracking may be used only on the Kinect sensor at index 0; you can use it on any one connected sensor per process.

    Skeleton tracking is available on the first sensor for which you call NuiInitialize with either NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX or NUI_INITIALIZE_FLAG_USES_SKELETON. After initializing a sensor with either (or both) of those flags, all attempts to do the same with any other sensor will return  E_NUI_SKELETAL_ENGINE_BUSY.

    John
    K4W Dev

    Tuesday, March 6, 2012 10:05 PM
  • Hey John,

    Thank you very much for your information. I did try, but the 2nd application won't track my skeleton automatically. Could you take a look at my code? I think it's generally very useful to know how to run multiple Kinects on a single desktop with ST capability on each of the Kinect.

    So, for the 1st c++ application, what I did was:
    HRESULT KinectGrabber::Kinect_Init() {
    
        InitializeCriticalSection(&cs);
        HRESULT hr,hr_init_0,hr0,hr_rgb_0;
    
         hr_init_0 = NuiCreateSensorByIndex(0, &m_pNuiSensor); // change this index to pick a different kinect
        if ( FAILED(hr_init_0) ){ return hr_init_0;}
        m_instanceId = m_pNuiSensor->NuiDeviceConnectionId();
    
        m_hNextVideoFrameEvent = CreateEvent( NULL, TRUE, FALSE, NULL );    
        m_hNextDepthFrameEvent = CreateEvent( NULL, TRUE, FALSE, NULL );   
        m_hNextSkeletonEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
    
        int num_kinects;
        hr = NuiGetSensorCount(&num_kinects);
        printf(" %d Kinetics found \n\n", num_kinects);
    
        hr0 = m_pNuiSensor->NuiInitialize(
            NUI_INITIALIZE_FLAG_USES_DEPTH |  NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX | NUI_INITIALIZE_FLAG_USES_COLOR |     NUI_INITIALIZE_FLAG_USES_SKELETON);
    
        if ( HasSkeletalEngine( m_pNuiSensor ) )
        {
            hr = m_pNuiSensor->NuiSkeletonTrackingEnable( m_hNextSkeletonEvent, 0 );
            if( FAILED( hr ) )
            {
                return hr;
            }
        }
       
        hr = m_pNuiSensor-> NuiImageStreamOpen(
            NUI_IMAGE_TYPE_COLOR,
            NUI_IMAGE_RESOLUTION_640x480,
            0,
            2,
            m_hNextVideoFrameEvent,
            &m_pVideoStreamHandle );
    
        hr = m_pNuiSensor-> NuiImageStreamOpen(
            NUI_IMAGE_TYPE_DEPTH,
            NUI_IMAGE_RESOLUTION_640x480,
            0,
            2,
            m_hNextDepthFrameEvent,
            &m_pDepthStreamHandle );
    
        
        //m_hThNuiProcess = CreateThread( NULL, 0, Kinect_Update, this, 0, NULL );
        m_hEvNuiProcessStop = CreateEvent( NULL, FALSE, FALSE, NULL );
    
    }
    



    In the 2nd application(another vs2010 solution in parallel), the only line I've changed is: I change this line from

    hr_init_0 = NuiCreateSensorByIndex(0, &m_pNuiSensor); // change this index to pick a different kinect

    to
    hr_init_0 = NuiCreateSensorByIndex(1, &m_pNuiSensor); // change this index to pick a different kinect

    The video and depth image works, but skeleton cannot be detected...
    Should I also modify something else except changing the index number, in order to get the ST to work in the second application?

    Lining YAO

    Wednesday, March 7, 2012 4:48 PM
  • Have you tried running 2 instances of the SkeletalViewer sample applicaiton with your hardware? You will need to comment out the statement block to make that work

    //if ( (hMutex != NULL) && (GetLastError() == ERROR_ALREADY_EXISTS) )
    //{
    ...
    //}

    Additionally, are you using Kinect for Windows hardware for both devices? Since you are using a depth image of 640x480, this is only going to work for the Kinect for Windows hardware.

    Tuesday, March 13, 2012 10:53 PM
  • Hi John,

    I met the  E_NUI_SKELETAL_ENGINE_BUSY problem when I was trying to use two kinects to track people.

    Is there any solution for that?

    Thanks

    Friday, June 1, 2012 9:45 AM