From 40d8d11f458c835108cd66897e0beeee620989f3 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Sat, 28 Apr 2012 11:33:01 +0000 Subject: [PATCH] fixed RGBD capture with Asus Xtion (by Gary Bradski) --- .../highgui/include/opencv2/highgui/highgui_c.h | 1 + modules/highgui/src/cap_openni.cpp | 24 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/modules/highgui/include/opencv2/highgui/highgui_c.h b/modules/highgui/include/opencv2/highgui/highgui_c.h index 2e61927..7937df4 100644 --- a/modules/highgui/include/opencv2/highgui/highgui_c.h +++ b/modules/highgui/include/opencv2/highgui/highgui_c.h @@ -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 diff --git a/modules/highgui/src/cap_openni.cpp b/modules/highgui/src/cap_openni.cpp index 3cc367a..739adf8 100644 --- a/modules/highgui/src/cap_openni.cpp +++ b/modules/highgui/src/cap_openni.cpp @@ -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 ) -- 2.7.4