renamed property of openni camera
This commit is contained in:
parent
c9489a8bf3
commit
baa81de122
@ -92,7 +92,7 @@ Since two types of sensor's data generators are supported (image generator and d
|
||||
|
||||
* 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.
|
||||
Some depth sensors (for example XtionPRO) do not have image generator. In order to check it you can get ``CV_CAP_OPENNI_IMAGE_GENERATOR_PRESENT`` property.
|
||||
::
|
||||
|
||||
bool isImageGeneratorPresent = capture.get( CV_CAP_PROP_OPENNI_IMAGE_GENERATOR_PRESENT ) != 0; // or == 1
|
||||
|
@ -388,7 +388,9 @@ enum
|
||||
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_PROP_OPENNI_IMAGE_GENERATOR_PRESENT = 105,
|
||||
CV_CAP_PROP_OPENNI_GENERATOR_PRESENT = 105,
|
||||
|
||||
CV_CAP_OPENNI_IMAGE_GENERATOR_PRESENT = CV_CAP_OPENNI_IMAGE_GENERATOR + CV_CAP_PROP_OPENNI_GENERATOR_PRESENT,
|
||||
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_FOCAL_LENGTH = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_FOCAL_LENGTH,
|
||||
|
@ -127,8 +127,9 @@ protected:
|
||||
// OpenNI context
|
||||
xn::Context context;
|
||||
bool m_isOpened;
|
||||
bool m_isDepthGeneratorPresent;
|
||||
bool m_isImageGeneratorPresent;
|
||||
|
||||
|
||||
// Data generators with its metadata
|
||||
xn::DepthGenerator depthGenerator;
|
||||
xn::DepthMetaData depthMetaData;
|
||||
@ -229,6 +230,21 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
|
||||
}
|
||||
|
||||
// Associate generators with context.
|
||||
// enumerate the nodes to find if depth generator is present
|
||||
xn::NodeInfoList depthList;
|
||||
status = context.EnumerateExistingNodes( depthList, XN_NODE_TYPE_DEPTH );
|
||||
if( status != XN_STATUS_OK )
|
||||
{
|
||||
std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to enumerate depth generators: "
|
||||
<< std::string(xnGetStatusString(status)) << std::endl;
|
||||
return;
|
||||
}
|
||||
if( depthList.IsEmpty() )
|
||||
{
|
||||
std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : The device doesn't have depth generator. Such devices aren't supported now." << std::endl;
|
||||
return;
|
||||
}
|
||||
m_isDepthGeneratorPresent = true;
|
||||
status = depthGenerator.Create( context );
|
||||
if( status != XN_STATUS_OK )
|
||||
{
|
||||
@ -238,8 +254,8 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
|
||||
}
|
||||
|
||||
// enumerate the nodes to find if image generator is present
|
||||
xn::NodeInfoList Imagelist;
|
||||
status = context.EnumerateExistingNodes( Imagelist, XN_NODE_TYPE_IMAGE );
|
||||
xn::NodeInfoList imageList;
|
||||
status = context.EnumerateExistingNodes( imageList, XN_NODE_TYPE_IMAGE );
|
||||
if( status != XN_STATUS_OK )
|
||||
{
|
||||
std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to enumerate image generators: "
|
||||
@ -247,10 +263,10 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
|
||||
return;
|
||||
}
|
||||
|
||||
if( !Imagelist.IsEmpty() )
|
||||
if( !imageList.IsEmpty() )
|
||||
{
|
||||
m_isImageGeneratorPresent = true;
|
||||
imageGenerator.Create( context );
|
||||
status = imageGenerator.Create( context );
|
||||
if( status != XN_STATUS_OK )
|
||||
{
|
||||
std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to create image generator: "
|
||||
@ -390,12 +406,18 @@ bool CvCapture_OpenNI::setProperty( int propIdx, double propValue )
|
||||
|
||||
double CvCapture_OpenNI::getDepthGeneratorProperty( int propIdx )
|
||||
{
|
||||
CV_Assert( depthGenerator.IsValid() );
|
||||
|
||||
double propValue = 0;
|
||||
if( !m_isDepthGeneratorPresent )
|
||||
return propValue;
|
||||
|
||||
CV_Assert( depthGenerator.IsValid() );
|
||||
|
||||
switch( propIdx )
|
||||
{
|
||||
case CV_CAP_PROP_OPENNI_GENERATOR_PRESENT :
|
||||
CV_Assert( m_isDepthGeneratorPresent );
|
||||
propValue = 1.;
|
||||
break;
|
||||
case CV_CAP_PROP_FRAME_WIDTH :
|
||||
propValue = depthOutputMode.nXRes;
|
||||
break;
|
||||
@ -417,7 +439,11 @@ double CvCapture_OpenNI::getDepthGeneratorProperty( int propIdx )
|
||||
case CV_CAP_PROP_OPENNI_REGISTRATION :
|
||||
propValue = depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) ? 1.0 : 0.0;
|
||||
default :
|
||||
CV_Error( CV_StsBadArg, "Depth generator does not support such parameter for getting.\n");
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Depth generator does not support such parameter (propIdx=" << propIdx << ") for getting.\n";
|
||||
CV_Error( CV_StsBadArg, ss.str().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
return propValue;
|
||||
@ -431,44 +457,48 @@ bool CvCapture_OpenNI::setDepthGeneratorProperty( int propIdx, double propValue
|
||||
|
||||
switch( propIdx )
|
||||
{
|
||||
case CV_CAP_PROP_OPENNI_REGISTRATION:
|
||||
case CV_CAP_PROP_OPENNI_REGISTRATION:
|
||||
{
|
||||
if( propValue != 0.0 ) // "on"
|
||||
{
|
||||
if( propValue != 0.0 ) // "on"
|
||||
// if there isn't image generator (i.e. ASUS XtionPro doesn't have it)
|
||||
// then the property isn't avaliable
|
||||
if( m_isImageGeneratorPresent )
|
||||
{
|
||||
// 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( !depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) )
|
||||
{
|
||||
CV_Assert( imageGenerator.IsValid() );
|
||||
if( !depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) )
|
||||
if( depthGenerator.GetAlternativeViewPointCap().IsViewPointSupported(imageGenerator) )
|
||||
{
|
||||
if( depthGenerator.GetAlternativeViewPointCap().IsViewPointSupported(imageGenerator) )
|
||||
{
|
||||
XnStatus status = depthGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator);
|
||||
if( status != XN_STATUS_OK )
|
||||
std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl;
|
||||
else
|
||||
isSet = true;
|
||||
}
|
||||
XnStatus status = depthGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator);
|
||||
if( status != XN_STATUS_OK )
|
||||
std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl;
|
||||
else
|
||||
std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : Unsupported viewpoint." << std::endl;
|
||||
isSet = true;
|
||||
}
|
||||
else
|
||||
isSet = true;
|
||||
std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : Unsupported viewpoint." << std::endl;
|
||||
}
|
||||
}
|
||||
else // "off"
|
||||
{
|
||||
XnStatus status = depthGenerator.GetAlternativeViewPointCap().ResetViewPoint();
|
||||
if( status != XN_STATUS_OK )
|
||||
std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl;
|
||||
else
|
||||
isSet = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
CV_Error( CV_StsBadArg, "Unsupported depth generator property.\n");
|
||||
else // "off"
|
||||
{
|
||||
XnStatus status = depthGenerator.GetAlternativeViewPointCap().ResetViewPoint();
|
||||
if( status != XN_STATUS_OK )
|
||||
std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl;
|
||||
else
|
||||
isSet = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Depth generator does not support such parameter (propIdx=" << propIdx << ") for setting.\n";
|
||||
CV_Error( CV_StsBadArg, ss.str().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
return isSet;
|
||||
@ -476,31 +506,35 @@ bool CvCapture_OpenNI::setDepthGeneratorProperty( int propIdx, double propValue
|
||||
|
||||
double CvCapture_OpenNI::getImageGeneratorProperty( int propIdx )
|
||||
{
|
||||
double propValue = 0;
|
||||
double propValue = 0.;
|
||||
if( !m_isImageGeneratorPresent )
|
||||
return propValue;
|
||||
|
||||
if( propIdx == CV_CAP_PROP_OPENNI_IMAGE_GENERATOR_PRESENT )
|
||||
propValue = m_isImageGeneratorPresent ? 1. : 0.;
|
||||
else
|
||||
{
|
||||
CV_Assert( imageGenerator.IsValid() );
|
||||
CV_Assert( imageGenerator.IsValid() );
|
||||
|
||||
switch( propIdx )
|
||||
{
|
||||
case CV_CAP_PROP_FRAME_WIDTH :
|
||||
propValue = imageOutputMode.nXRes;
|
||||
break;
|
||||
case CV_CAP_PROP_FRAME_HEIGHT :
|
||||
propValue = imageOutputMode.nYRes;
|
||||
break;
|
||||
case CV_CAP_PROP_FPS :
|
||||
propValue = imageOutputMode.nFPS;
|
||||
break;
|
||||
default :
|
||||
CV_Error( CV_StsBadArg, "Image generator does not support such parameter for getting.\n");
|
||||
}
|
||||
switch( propIdx )
|
||||
{
|
||||
case CV_CAP_PROP_OPENNI_GENERATOR_PRESENT :
|
||||
CV_Assert( m_isImageGeneratorPresent );
|
||||
propValue = 1.;
|
||||
break;
|
||||
case CV_CAP_PROP_FRAME_WIDTH :
|
||||
propValue = imageOutputMode.nXRes;
|
||||
break;
|
||||
case CV_CAP_PROP_FRAME_HEIGHT :
|
||||
propValue = imageOutputMode.nYRes;
|
||||
break;
|
||||
case CV_CAP_PROP_FPS :
|
||||
propValue = imageOutputMode.nFPS;
|
||||
break;
|
||||
default :
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Image generator does not support such parameter (propIdx=" << propIdx << ") for getting.\n";
|
||||
CV_Error( CV_StsBadArg, ss.str().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
return propValue;
|
||||
}
|
||||
|
||||
@ -550,7 +584,11 @@ bool CvCapture_OpenNI::setImageGeneratorProperty( int propIdx, double propValue
|
||||
break;
|
||||
}
|
||||
default:
|
||||
CV_Error( CV_StsBadArg, "Unsupported image generator property.\n");
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Image generator does not support such parameter (propIdx=" << propIdx << ") for setting.\n";
|
||||
CV_Error( CV_StsBadArg, ss.str().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
return isSet;
|
||||
|
@ -208,7 +208,7 @@ int main( int argc, char* argv[] )
|
||||
"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;
|
||||
if( capture.get( CV_CAP_PROP_OPENNI_IMAGE_GENERATOR_PRESENT ) )
|
||||
if( capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR_PRESENT ) )
|
||||
{
|
||||
cout <<
|
||||
"\nImage generator output mode:" << endl <<
|
||||
@ -218,7 +218,7 @@ int main( int argc, char* argv[] )
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "\nDevice doesn't contain image generator" << endl;
|
||||
cout << "\nDevice doesn't contain image generator." << endl;
|
||||
if (!retrievedImageFlags[0] && !retrievedImageFlags[1] && !retrievedImageFlags[2])
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user