fixed RGBD capture with Asus Xtion (by Gary Bradski)
authorVadim Pisarevsky <no@email>
Sat, 28 Apr 2012 11:33:01 +0000 (11:33 +0000)
committerVadim Pisarevsky <no@email>
Sat, 28 Apr 2012 11:33:01 +0000 (11:33 +0000)
modules/highgui/include/opencv2/highgui/highgui_c.h
modules/highgui/src/cap_openni.cpp

index 2e61927..7937df4 100644 (file)
@@ -300,6 +300,7 @@ enum
     CV_CAP_PVAPI    =800,   // PvAPI, Prosilica GigE SDK
 
     CV_CAP_OPENNI   =900,   // OpenNI (for Kinect)
+    CV_CAP_OPENNI_ASUS =910,   // OpenNI (for Asus Xtion)
 
     CV_CAP_ANDROID  =1000,  // Android
     
index 3cc367a..739adf8 100644 (file)
@@ -409,10 +409,11 @@ private:
 class CvCapture_OpenNI : public CvCapture
 {
 public:
+    enum { DEVICE_DEFAULT=0, DEVICE_MS_KINECT=0, DEVICE_ASUS_XTION=1, DEVICE_MAX=1 };
+    
     static const int INVALID_PIXEL_VAL = 0;
     static const int INVALID_COORDINATE_VAL = 0;
 
-
 #ifdef HAVE_TBB
     static const int DEFAULT_MAX_BUFFER_SIZE = 8;
 #else
@@ -516,14 +517,25 @@ XnMapOutputMode defaultMapOutputMode()
     return mode;
 }
 
+
 CvCapture_OpenNI::CvCapture_OpenNI( int index )
 {
+    int deviceType = DEVICE_DEFAULT;
     XnStatus status;
-
+    
     isContextOpened = false;
     maxBufferSize = DEFAULT_MAX_BUFFER_SIZE;
     isCircleBuffer = DEFAULT_IS_CIRCLE_BUFFER;
     maxTimeDuration = DEFAULT_MAX_TIME_DURATION;
+    
+    if( index >= 10 )
+    {
+        deviceType = index / 10;
+        index %= 10;
+    }
+
+    if( deviceType > DEVICE_MAX )
+        return;
 
     // Initialize and configure the context.
     status = context.Init();
@@ -620,6 +632,14 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
         CV_DbgAssert( imageGenerator.SetMapOutputMode(defaultMapOutputMode()) == XN_STATUS_OK );
     }
 
+    if( deviceType == DEVICE_ASUS_XTION )
+    {
+        //ps/asus specific
+        imageGenerator.SetIntProperty("InputFormat", 1 /*XN_IO_IMAGE_FORMAT_YUV422*/);
+        imageGenerator.SetPixelFormat(XN_PIXEL_FORMAT_RGB24);
+        depthGenerator.SetIntProperty("RegistrationType", 1 /*XN_PROCESSING_HARDWARE*/);
+    }
+
     //  Start generating data.
     status = context.StartGeneratingAll();
     if( status != XN_STATUS_OK )