.. highlight:: cpp
-Using depth sensors
-===================
+Using Kinect and other OpenNI compatible depth sensors
+======================================================
Depth sensors compatible with OpenNI (Kinect, XtionPRO, ...) are supported through ``VideoCapture`` class. Depth map, RGB image and some other formats of output can be retrieved by using familiar interface of ``VideoCapture``.
* CV_CAP_OPENNI_DEPTH_GENERATOR -- A flag for access to the depth generator properties. This flag value is assumed by default if neither of the two possible values of the property is not set.
-Some depth sensors (for example XtionPRO) do not have image generator. In order to check it you can get ``CV_CAP_OPENNI_PROP_IMAGE_GENERATOR_PRESENT`` property. If returned value greater than zero sensor has image generator.
+Some depth sensors (for example XtionPRO) do not have image generator. In order to check it you can get ``CV_CAP_OPENNI_PROP_IMAGE_GENERATOR_PRESENT`` property.
::
- bool isImageGeneratorPresent = capture.get( CV_CAP_OPENNI_PROP_IMAGE_GENERATOR_PRESENT ) > 0;
+ bool isImageGeneratorPresent = capture.get( CV_CAP_OPENNI_PROP_IMAGE_GENERATOR_PRESENT ) != 0; // or == 1
Flags specifing the needed generator type must be used in combination with particular generator property. The following properties of cameras available through OpenNI interfaces are supported:
{
CV_Assert( depthGenerator.IsValid() );
- double res = 0;
+ double propValue = 0;
+
switch( propIdx )
{
case CV_CAP_PROP_FRAME_WIDTH :
- res = depthOutputMode.nXRes;
+ propValue = depthOutputMode.nXRes;
break;
case CV_CAP_PROP_FRAME_HEIGHT :
- res = depthOutputMode.nYRes;
+ propValue = depthOutputMode.nYRes;
break;
case CV_CAP_PROP_FPS :
- res = depthOutputMode.nFPS;
+ propValue = depthOutputMode.nFPS;
break;
case CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH :
- res = depthGenerator.GetDeviceMaxDepth();
+ propValue = depthGenerator.GetDeviceMaxDepth();
break;
case CV_CAP_PROP_OPENNI_BASELINE :
- res = baseline;
+ propValue = baseline;
break;
case CV_CAP_PROP_OPENNI_FOCAL_LENGTH :
- res = (double)depthFocalLength_VGA;
+ propValue = (double)depthFocalLength_VGA;
break;
case CV_CAP_PROP_OPENNI_REGISTRATION :
- res = depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) ? 1.0 : 0.0;
+ propValue = depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) ? 1.0 : 0.0;
default :
CV_Error( CV_StsBadArg, "Depth generator does not support such parameter for getting.\n");
}
- return res;
+ return propValue;
}
bool CvCapture_OpenNI::setDepthGeneratorProperty( int propIdx, double propValue )
{
- bool res = false;
+ bool isSet = false;
CV_Assert( depthGenerator.IsValid() );
{
if( propValue != 0.0 ) // "on"
{
- // if no Image Generator is present i.e. ASUS XtionPro the imageGenerator cannot be used
+ // if there isn't image generator (i.e. ASUS XtionPro doesn't have it)
+ // then the property isn't avaliable
if( m_isImageGeneratorPresent )
{
CV_Assert( imageGenerator.IsValid() );
if( status != XN_STATUS_OK )
std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl;
else
- res = true;
+ isSet = true;
}
else
std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : Unsupported viewpoint." << std::endl;
}
else
- res = true;
+ isSet = true;
}
- else
- res = false;
}
else // "off"
{
if( status != XN_STATUS_OK )
std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl;
else
- res = true;
+ isSet = true;
}
}
break;
CV_Error( CV_StsBadArg, "Unsupported depth generator property.\n");
}
- return res;
+ return isSet;
}
double CvCapture_OpenNI::getImageGeneratorProperty( int propIdx )
{
- double res = 0;
+ double propValue = 0;
+ if( !m_isImageGeneratorPresent )
+ return propValue;
- if (propIdx == CV_CAP_PROP_IMAGE_GENERATOR_PRESENT)
- res = m_isImageGeneratorPresent ? 1 : -1;
+ if( propIdx == CV_CAP_PROP_IMAGE_GENERATOR_PRESENT )
+ propValue = m_isImageGeneratorPresent ? 1. : 0.;
else
- {
- if (!m_isImageGeneratorPresent)
- return res;
-
+ {
CV_Assert( imageGenerator.IsValid() );
switch( propIdx )
{
case CV_CAP_PROP_FRAME_WIDTH :
- res = imageOutputMode.nXRes;
+ propValue = imageOutputMode.nXRes;
break;
case CV_CAP_PROP_FRAME_HEIGHT :
- res = imageOutputMode.nYRes;
+ propValue = imageOutputMode.nYRes;
break;
case CV_CAP_PROP_FPS :
- res = imageOutputMode.nFPS;
+ propValue = imageOutputMode.nFPS;
break;
default :
CV_Error( CV_StsBadArg, "Image generator does not support such parameter for getting.\n");
}
}
- return res;
+ return propValue;
}
bool CvCapture_OpenNI::setImageGeneratorProperty( int propIdx, double propValue )
{
- bool res = false;
- if(!m_isImageGeneratorPresent)
- return res;
-
+ bool isSet = false;
+ if( !m_isImageGeneratorPresent )
+ return isSet;
+
CV_Assert( imageGenerator.IsValid() );
switch( propIdx )
else
{
imageOutputMode = newImageOutputMode;
- res = true;
+ isSet = true;
}
break;
}
CV_Error( CV_StsBadArg, "Unsupported image generator property.\n");
}
- return res;
+ return isSet;
}
bool CvCapture_OpenNI::grabFrame()
return false;
depthGenerator.GetMetaData( depthMetaData );
- if(m_isImageGeneratorPresent)
+ if( m_isImageGeneratorPresent )
imageGenerator.GetMetaData( imageMetaData );
+
return true;
}
"FRAME_HEIGHT " << capture.get( CV_CAP_PROP_FRAME_HEIGHT ) << endl <<
"FRAME_MAX_DEPTH " << capture.get( CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH ) << " mm" << endl <<
"FPS " << capture.get( CV_CAP_PROP_FPS ) << endl;
- bool isImageGeneratorPresent = capture.get( CV_CAP_OPENNI_PROP_IMAGE_GENERATOR_PRESENT ) > 0;
- if (isImageGeneratorPresent)
- cout << "\nImage generator output mode:" << endl <<
+ if( capture.get( CV_CAP_OPENNI_PROP_IMAGE_GENERATOR_PRESENT ) )
+ {
+ cout <<
+ "\nImage generator output mode:" << endl <<
"FRAME_WIDTH " << capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FRAME_WIDTH ) << endl <<
"FRAME_HEIGHT " << capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FRAME_HEIGHT ) << endl <<
"FPS " << capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FPS ) << endl;
+ }
else
{
cout << "\nDevice doesn't contain image generator" << endl;