none
Two applications - Two Kinects - Timeout RRS feed

  • Question

  • Hey everyone, 

    I post a new thread because my problem seems different from other with two kinects and two applications. 

    I try to run two instances of the same application in order to have the skeleton tracking with two Kinects. (Before that, I tried to make a single application and my two Kinects worked fine together, but not the skeleton tracking of course). 

    For the first Kinect, everything is ok.

    When I run the second instance with the second Kinect, the initialization is ok, but after tree turns, no more color event appears, the WaitForSingleOject() method always return WAIT_TIMEOUT. I checked for depth and skeleton events, and the Kinect still sends its. 

    It doesn't seems to be an USB controller problem, beacuse I can run an application using two kinects in the same time.

    I'm pretty lost with this difficulty, any help is welcome ! Thanks  



    Tuesday, November 26, 2013 10:44 AM

Answers

  • Based on the way you setup your wait loop, the behavior you are seeing is expected. The Kinect only provides data at 30fps(33.3333ms). Your loop may be executing a lot faster than that. Additionally, there is no guarantee color and depth/skeleton will be ready at the same time. So one or 2 of the events would be set but not all.

    You may want to review how WaitForMultipleObjects works, since you are waiting for a period of 0 and using bWaitAll = false, there is a good change that none of the events(frames) are ready yet.

    Ignore the wait and keep going or redesign to work with a event based model instead. Given the extra load the system has to handle 2 Kinect streams of data, you may have a performance issue to process any facetracking data in a timely manner.

    http://msdn.microsoft.com/en-us/library/hh973076.aspx


    Carmine Sirignano - MSFT

    Thursday, January 9, 2014 7:16 PM

All replies

  • You cannot run 2 Kinect devices on the same USB2 Host Controller. One connection can use up to 60% of the available bandwidth of USB2, so trying to run 2 at the same time will fail.

    You can check your system for host controllers, but using device manager and sorting the list by connection(View Menu -> View by connection). Drill down into the tree under for "USB2 Enhanced Host Controller #". Be sure the Kinect devices do not appear under the same one.


    Carmine Sirignano - MSFT

    Tuesday, November 26, 2013 8:05 PM
  • You're right my two Kinects are under the same host controller, but I tried my application on another computer where each Kinect was on a different USB controller and I had the same error ... 

    Furthermore, the application works if I connect two Kinects and use only the first one. 


    Tuesday, November 26, 2013 8:25 PM
  • You can certainly have 2 Kinects connected to the PC at the same time, on the same host controller. You cannot have 2 running at the same time on the same host controller. If you want both to operate at the same time, they must be on separate host controllers.

    If you have them on different host controllers and still have an issue. Once you have ensured they are connected, run Kinect Explorer from the Kinect for Windows Toolkit Browser. You should have 2 windows, 1 for each sensor connected.


    Carmine Sirignano - MSFT

    Wednesday, November 27, 2013 11:08 PM
  • With Kinect Explorer, everything is fine, on one and two controllers ...
    Thursday, November 28, 2013 3:31 PM
  • Does anyone has an idea ? 

    I still cannot find the origin of the problem. With Kinect Explorer I can see two windows for my two kinects, but with my application, the second kinect doesn't send color thread. 

    Thanks for any help. 

    Monday, January 6, 2014 1:26 PM
  • Without any code, you have not provided enough information on how you are calling the api's. Are you using the correct handle with the right device? We have no context on how you developed the application so we don't know how you are creating the issue.

    As the Kinect Explorer demonstrated, you can run 2 instances and get data, so you may need to follow this model (separate thread for each sensor). If you need to compare data from one to the other, you need to marshal that data yourself.


    Carmine Sirignano - MSFT

    Tuesday, January 7, 2014 11:30 PM
  • I'm sorry, I didn't want to drown my question with too many code ... But you're right it's difficult to give an answer if there is no details. 

    To initialize the sensor : 

    HRESULT CKinect::init()
    {
    	INuiSensor * pNuiSensor;
    	int iSensorCount; 
    
    	HRESULT hr = NuiGetSensorCount(&iSensorCount);
    	if (FAILED(hr))
    	{
    		return hr;
    	}
    
    	// Look at each Kinect sensor
        for (int i = 0; i < iSensorCount; ++i)
        {
            // Create the sensor so we can check status, if we can't create it, move on to the next
            hr = NuiCreateSensorByIndex(i, &pNuiSensor);
            if (FAILED(hr))
            {
                continue;
            }
    
            // Get the status of the sensor, and if connected, then we can initialize it
            hr = pNuiSensor->NuiStatus();
    		if (FAILED(hr))
            {
                continue;
            }
    
    		//Check if the kinect is already used by another instance, if we can't initialize it, move on to the next
    		hr = pNuiSensor->NuiInitialize(NUI_INITIALIZE_FLAG_USES_COLOR);
            if (S_OK == hr)
            {
                m_sensor = pNuiSensor;
    			m_iSensorIndex = i;
                break;
            }
    		 
            // This sensor wasn't OK, so release it since we're not using it
            pNuiSensor->Release();
        }
    
    	if (NULL != m_sensor)
    	{
    		 // Initialize the Kinect and specify that we'll be using color
            hr = m_sensor->NuiInitialize(NUI_INITIALIZE_FLAG_USES_COLOR | NUI_INITIALIZE_FLAG_USES_SKELETON | NUI_INITIALIZE_FLAG_USES_DEPTH | NUI_INITIALIZE_FLAG_USES_AUDIO);
    
    		if (SUCCEEDED(hr))
    		{
    			/// COLOR INIT ///
    			// Create an event that will be signaled when color data is available
                m_hNextColorFrameEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    
                // Open a color image stream to receive color frames
                hr = m_sensor->NuiImageStreamOpen(
                    NUI_IMAGE_TYPE_COLOR,
    				RESOLUTION,
                    0,
                    2,
                    m_hNextColorFrameEvent,
                    &m_pColorStreamHandle);
    		
    
    //[...] Depth, Skeleton and Audio initialization 
    
    		}
    	}
    
    	return hr;
    }

    Then at each turn, I update each event : 

    HRESULT CKinect::update()    
    {
    	HRESULT hr = E_FAIL;
    
    	if (NULL == m_sensor)
        {
            return hr;
        }
    
    	// Configure events to be listened on
    	HANDLE hEvents[3];
    	hEvents[0] = m_hNextColorFrameEvent;
    	hEvents[1] = m_hNextDepthFrameEvent;
    	hEvents[2] = m_hNextSkeletonEvent;
    
    	WaitForMultipleObjects(sizeof(hEvents)/sizeof(hEvents[0]), hEvents, FALSE, 100);
    
    	// Process signal events
        if (WAIT_OBJECT_0 == WaitForSingleObject(m_hNextColorFrameEvent, 0))
    	{
    		std::cout << "WAIT_OK"<<endl;
            hr = processColor();
    	}
    	else if( WAIT_TIMEOUT == WaitForSingleObject(m_hNextColorFrameEvent, 0))
    		std::cout << "WAIT_TIMEOUT"<<endl;
    
    	if (SUCCEEDED(hr)) 
    	{
    		if (WAIT_OBJECT_0 == WaitForSingleObject(m_hNextDepthFrameEvent, 0))
    		{
    			hr = processDepth(); 
    			if(SUCCEEDED(hr)) 
    			{
    				if (WAIT_OBJECT_0 == WaitForSingleObject(m_hNextSkeletonEvent, 0))
    				{
    					hr = processSkeleton(); 
    					if(SUCCEEDED(hr))
    						hr = processFace(); 
    				}
    			}
    		}
    	}
    
    	return hr; 
    
    }

    I run my application the first time, and it connects to the first connected kinect. Everything works fine; 

    When  I run the application a second time, it connects to the second kinect and I obtain this in command center : 

    WAIT_OK

    WAIT_OK

    WAIT_OK 

    WAIT_OK

    WAIT_TIMEOUT

    WAIT_TIMEOUT ... 


    I hope these will be helpful, thanks very much for your help. 


    Wednesday, January 8, 2014 12:36 PM
  • Based on the way you setup your wait loop, the behavior you are seeing is expected. The Kinect only provides data at 30fps(33.3333ms). Your loop may be executing a lot faster than that. Additionally, there is no guarantee color and depth/skeleton will be ready at the same time. So one or 2 of the events would be set but not all.

    You may want to review how WaitForMultipleObjects works, since you are waiting for a period of 0 and using bWaitAll = false, there is a good change that none of the events(frames) are ready yet.

    Ignore the wait and keep going or redesign to work with a event based model instead. Given the extra load the system has to handle 2 Kinect streams of data, you may have a performance issue to process any facetracking data in a timely manner.

    http://msdn.microsoft.com/en-us/library/hh973076.aspx


    Carmine Sirignano - MSFT

    Thursday, January 9, 2014 7:16 PM