added ability to reset view point of depth generator to normal one (#1195)

pull/13383/head
Maria Dimashova 14 years ago
parent 4d8a261d99
commit b64bb95860
  1. 5
      modules/highgui/include/opencv2/highgui/highgui_c.h
  2. 68
      modules/highgui/src/cap_openni.cpp

@ -360,7 +360,10 @@ enum
CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH = 101, // in mm CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH = 101, // in mm
CV_CAP_PROP_OPENNI_BASELINE = 102, // in mm CV_CAP_PROP_OPENNI_BASELINE = 102, // in mm
CV_CAP_PROP_OPENNI_FOCAL_LENGTH = 103, // in pixels CV_CAP_PROP_OPENNI_FOCAL_LENGTH = 103, // in pixels
CV_CAP_PROP_OPENNI_REGISTRATION_ON = 104, // flag CV_CAP_PROP_OPENNI_REGISTRATION_ON = 104, // flag
CV_CAP_PROP_OPENNI_REGISTRATION = CV_CAP_PROP_OPENNI_REGISTRATION_ON, // flag that synchronizes the remapping depth map to image map
// by changing depth generator's view point (if the flag is "on") or
// sets this view point to its normal one (if the flag is "off").
CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE = CV_CAP_OPENNI_IMAGE_GENERATOR + CV_CAP_PROP_OPENNI_OUTPUT_MODE, CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE = CV_CAP_OPENNI_IMAGE_GENERATOR + CV_CAP_PROP_OPENNI_OUTPUT_MODE,
CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_BASELINE, CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_BASELINE,
CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_FOCAL_LENGTH, CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_FOCAL_LENGTH,

@ -228,7 +228,7 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
// Set map output mode. // Set map output mode.
CV_Assert( depthGenerator.SetMapOutputMode( depthOutputMode ) == XN_STATUS_OK ); // xn::DepthGenerator supports VGA only! (Jan 2011) CV_Assert( depthGenerator.SetMapOutputMode( depthOutputMode ) == XN_STATUS_OK ); // xn::DepthGenerator supports VGA only! (Jan 2011)
CV_Assert( imageGenerator.SetMapOutputMode( imageOutputMode ) == XN_STATUS_OK ); CV_Assert( imageGenerator.SetMapOutputMode( imageOutputMode ) == XN_STATUS_OK );
CV_Assert( depthGenerator.GetAlternativeViewPointCap().SetViewPoint( imageGenerator ) == XN_STATUS_OK ); CV_Assert( setProperty(CV_CAP_PROP_OPENNI_REGISTRATION, 1.0) );
// Start generating data. // Start generating data.
status = context.StartGeneratingAll(); status = context.StartGeneratingAll();
@ -360,30 +360,48 @@ double CvCapture_OpenNI::getDepthGeneratorProperty( int propIdx )
bool CvCapture_OpenNI::setDepthGeneratorProperty( int propIdx, double propValue ) bool CvCapture_OpenNI::setDepthGeneratorProperty( int propIdx, double propValue )
{ {
bool res = false;
CV_Assert( depthGenerator.IsValid() ); CV_Assert( depthGenerator.IsValid() );
switch(propIdx)
switch( propIdx )
{ {
case CV_CAP_PROP_OPENNI_REGISTRATION_ON: case CV_CAP_PROP_OPENNI_REGISTRATION:
{ {
CV_Assert( imageGenerator.IsValid() ); if( propValue != 0.0 ) // "on"
if (!depthGenerator.GetAlternativeViewPointCap ().IsViewPointAs (imageGenerator))
{ {
if (depthGenerator.GetAlternativeViewPointCap ().IsViewPointSupported (imageGenerator)) CV_Assert( imageGenerator.IsValid() );
if( !depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) )
{ {
XnStatus status = depthGenerator.GetAlternativeViewPointCap().SetViewPoint (imageGenerator); if( depthGenerator.GetAlternativeViewPointCap().IsViewPointSupported(imageGenerator) )
if (status != XN_STATUS_OK) {
CV_Error( CV_StsError, std::string("turning registration on failed. Reason: ") + xnGetStatusString (status)); XnStatus status = depthGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator);
if( status != XN_STATUS_OK )
std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl;
else
res = true;
}
else
std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : Unsupported viewpoint." << std::endl;
} }
else else
CV_Error( CV_StsError, "turning registration on failed. Reason: unsupported viewpoint"); res = true;
}
else // "off"
{
XnStatus status = depthGenerator.GetAlternativeViewPointCap().ResetViewPoint();
if( status != XN_STATUS_OK )
std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl;
else
res = true;
} }
} }
return true;
break; break;
default: default:
CV_Error( CV_StsBadArg, "Depth generator does not support such parameter for setting.\n"); CV_Error( CV_StsBadArg, "Unsupported depth generator property.\n");
} }
return false;
return res;
} }
double CvCapture_OpenNI::getImageGeneratorProperty( int propIdx ) double CvCapture_OpenNI::getImageGeneratorProperty( int propIdx )
@ -414,10 +432,13 @@ bool CvCapture_OpenNI::setImageGeneratorProperty( int propIdx, double propValue
bool res = false; bool res = false;
CV_Assert( imageGenerator.IsValid() ); CV_Assert( imageGenerator.IsValid() );
XnMapOutputMode newImageOutputMode = imageOutputMode;
switch( propIdx ) switch( propIdx )
{ {
case CV_CAP_PROP_OPENNI_OUTPUT_MODE : case CV_CAP_PROP_OPENNI_OUTPUT_MODE :
{
XnMapOutputMode newImageOutputMode = imageOutputMode;
switch( cvRound(propValue) ) switch( cvRound(propValue) )
{ {
case CV_CAP_OPENNI_VGA_30HZ : case CV_CAP_OPENNI_VGA_30HZ :
@ -433,16 +454,19 @@ bool CvCapture_OpenNI::setImageGeneratorProperty( int propIdx, double propValue
default : default :
CV_Error( CV_StsBadArg, "Unsupported image generator output mode.\n"); CV_Error( CV_StsBadArg, "Unsupported image generator output mode.\n");
} }
break;
default: XnStatus status = imageGenerator.SetMapOutputMode( newImageOutputMode );
CV_Error( CV_StsBadArg, "Image generator does not support such parameter for setting.\n"); if( status != XN_STATUS_OK )
std::cerr << "CvCapture_OpenNI::setImageGeneratorProperty : " << xnGetStatusString(status) << std::endl;
else
{
imageOutputMode = newImageOutputMode;
res = true;
}
break;
} }
default:
if( imageGenerator.SetMapOutputMode( newImageOutputMode ) == XN_STATUS_OK ) CV_Error( CV_StsBadArg, "Unsupported image generator property.\n");
{
imageOutputMode = newImageOutputMode;
res = true;
} }
return res; return res;

Loading…
Cancel
Save