mirror of
https://github.com/opencv/opencv.git
synced 2025-06-09 10:40:46 +08:00
Kinect2 support added to OpenNI2 backend (#11794)
* Kinect2 support added to OpenNI2 backend * more fixes for OpenNI2 backend * whitespace fixed * libfreenect2 support added * const cast added * mutable removed
This commit is contained in:
parent
df38624e10
commit
18bc2a1a93
@ -70,6 +70,35 @@
|
|||||||
#include "PS1080.h"
|
#include "PS1080.h"
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
static cv::Mutex initOpenNI2Mutex;
|
||||||
|
|
||||||
|
struct OpenNI2Initializer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void init()
|
||||||
|
{
|
||||||
|
cv::AutoLock al(initOpenNI2Mutex);
|
||||||
|
static OpenNI2Initializer initializer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
OpenNI2Initializer()
|
||||||
|
{
|
||||||
|
// Initialize and configure the context.
|
||||||
|
openni::Status status = openni::OpenNI::initialize();
|
||||||
|
if (status != openni::STATUS_OK)
|
||||||
|
{
|
||||||
|
CV_Error(CV_StsError, std::string("Failed to initialize:") + openni::OpenNI::getExtendedError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~OpenNI2Initializer()
|
||||||
|
{
|
||||||
|
openni::OpenNI::shutdown();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class CvCapture_OpenNI2 : public CvCapture
|
class CvCapture_OpenNI2 : public CvCapture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -107,6 +136,8 @@ protected:
|
|||||||
|
|
||||||
static openni::VideoMode defaultStreamOutputMode(int stream);
|
static openni::VideoMode defaultStreamOutputMode(int stream);
|
||||||
|
|
||||||
|
CvCapture_OpenNI2(int index, const char * filename);
|
||||||
|
|
||||||
IplImage* retrieveDepthMap();
|
IplImage* retrieveDepthMap();
|
||||||
IplImage* retrievePointCloudMap();
|
IplImage* retrievePointCloudMap();
|
||||||
IplImage* retrieveDisparityMap();
|
IplImage* retrieveDisparityMap();
|
||||||
@ -116,8 +147,8 @@ protected:
|
|||||||
IplImage* retrieveGrayImage();
|
IplImage* retrieveGrayImage();
|
||||||
IplImage* retrieveIrImage();
|
IplImage* retrieveIrImage();
|
||||||
|
|
||||||
openni::Status toggleStream(int stream, bool toggle);
|
void toggleStream(int stream, bool toggle);
|
||||||
bool readCamerasParams();
|
void readCamerasParams();
|
||||||
|
|
||||||
double getDepthGeneratorProperty(int propIdx) const;
|
double getDepthGeneratorProperty(int propIdx) const;
|
||||||
bool setDepthGeneratorProperty(int propIdx, double propVal);
|
bool setDepthGeneratorProperty(int propIdx, double propVal);
|
||||||
@ -131,12 +162,11 @@ protected:
|
|||||||
// OpenNI context
|
// OpenNI context
|
||||||
openni::Device device;
|
openni::Device device;
|
||||||
bool isContextOpened;
|
bool isContextOpened;
|
||||||
openni::Recorder recorder;
|
|
||||||
|
|
||||||
// Data generators with its metadata
|
// Data generators with its metadata
|
||||||
openni::VideoStream streams[CV_MAX_NUM_STREAMS];
|
std::vector<openni::VideoStream> streams;
|
||||||
openni::VideoFrameRef streamFrames[CV_MAX_NUM_STREAMS];
|
std::vector<openni::VideoFrameRef> streamFrames;
|
||||||
cv::Mat streamImages[CV_MAX_NUM_STREAMS];
|
std::vector<cv::Mat> streamImages;
|
||||||
|
|
||||||
int maxBufferSize, maxTimeDuration; // for approx sync
|
int maxBufferSize, maxTimeDuration; // for approx sync
|
||||||
bool isCircleBuffer;
|
bool isCircleBuffer;
|
||||||
@ -191,80 +221,103 @@ openni::VideoMode CvCapture_OpenNI2::defaultStreamOutputMode(int stream)
|
|||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
CvCapture_OpenNI2::CvCapture_OpenNI2( int index )
|
|
||||||
|
CvCapture_OpenNI2::CvCapture_OpenNI2(int index) :
|
||||||
|
CvCapture_OpenNI2(index, nullptr)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
CvCapture_OpenNI2::CvCapture_OpenNI2(const char * filename) :
|
||||||
|
CvCapture_OpenNI2(-1, filename)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
CvCapture_OpenNI2::CvCapture_OpenNI2(int index, const char * filename) :
|
||||||
|
device(),
|
||||||
|
isContextOpened(false),
|
||||||
|
streams(CV_MAX_NUM_STREAMS),
|
||||||
|
streamFrames(CV_MAX_NUM_STREAMS),
|
||||||
|
streamImages(CV_MAX_NUM_STREAMS),
|
||||||
|
maxBufferSize(DEFAULT_MAX_BUFFER_SIZE),
|
||||||
|
maxTimeDuration(DEFAULT_MAX_TIME_DURATION),
|
||||||
|
isCircleBuffer(DEFAULT_IS_CIRCLE_BUFFER),
|
||||||
|
baseline(0),
|
||||||
|
depthFocalLength_VGA(0),
|
||||||
|
shadowValue(0),
|
||||||
|
noSampleValue(0),
|
||||||
|
outputMaps(outputMapsTypesCount)
|
||||||
{
|
{
|
||||||
const char* deviceURI = openni::ANY_DEVICE;
|
|
||||||
openni::Status status;
|
|
||||||
int deviceType = DEVICE_DEFAULT;
|
|
||||||
|
|
||||||
noSampleValue = shadowValue = 0;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize and configure the context.
|
// Initialize and configure the context.
|
||||||
status = openni::OpenNI::initialize();
|
OpenNI2Initializer::init();
|
||||||
|
|
||||||
if (status != openni::STATUS_OK)
|
const char* deviceURI = openni::ANY_DEVICE;
|
||||||
|
bool needColor = true;
|
||||||
|
bool needIR = true;
|
||||||
|
if (index >= 0)
|
||||||
{
|
{
|
||||||
CV_Error(CV_StsError, cv::format("Failed to initialize:", openni::OpenNI::getExtendedError()));
|
int deviceType = DEVICE_DEFAULT;
|
||||||
return;
|
if (index >= 10)
|
||||||
}
|
{
|
||||||
|
deviceType = index / 10;
|
||||||
// find appropriate device URI
|
index %= 10;
|
||||||
openni::Array<openni::DeviceInfo> ldevs;
|
}
|
||||||
if (index > 0)
|
// Asus XTION and Occipital Structure Sensor do not have an image generator
|
||||||
{
|
needColor = (deviceType != DEVICE_ASUS_XTION);
|
||||||
openni::OpenNI::enumerateDevices(&ldevs);
|
|
||||||
deviceURI = ldevs[index].getUri();
|
// find appropriate device URI
|
||||||
|
openni::Array<openni::DeviceInfo> ldevs;
|
||||||
|
if (index > 0)
|
||||||
|
{
|
||||||
|
openni::OpenNI::enumerateDevices(&ldevs);
|
||||||
|
if (index < ldevs.getSize())
|
||||||
|
deviceURI = ldevs[index].getUri();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CV_Error(CV_StsError, "OpenCVKinect2: Device index exceeds the number of available OpenNI devices");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
deviceURI = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openni::Status status;
|
||||||
status = device.open(deviceURI);
|
status = device.open(deviceURI);
|
||||||
if( status != openni::STATUS_OK )
|
|
||||||
{
|
|
||||||
CV_Error(CV_StsError, cv::format("OpenCVKinect: Device open failed see: %s\n", openni::OpenNI::getExtendedError()));
|
|
||||||
openni::OpenNI::shutdown();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = toggleStream(CV_DEPTH_STREAM, true);
|
|
||||||
// Asus XTION and Occipital Structure Sensor do not have an image generator
|
|
||||||
if (deviceType != DEVICE_ASUS_XTION)
|
|
||||||
status = openni::Status(status | toggleStream(CV_COLOR_STREAM, true));
|
|
||||||
if (status != openni::STATUS_OK)
|
if (status != openni::STATUS_OK)
|
||||||
{
|
{
|
||||||
openni::OpenNI::shutdown();
|
CV_Error(CV_StsError, std::string("OpenCVKinect2: Failed to open device: ") + openni::OpenNI::getExtendedError());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!readCamerasParams())
|
toggleStream(CV_DEPTH_STREAM, true);
|
||||||
{
|
if (needColor)
|
||||||
CV_Error(CV_StsError, cv::format("CvCapture_OpenNI2::CvCapture_OpenNI2 : Could not read cameras parameters\n"));
|
toggleStream(CV_COLOR_STREAM, true);
|
||||||
return;
|
if (needIR)
|
||||||
}
|
toggleStream(CV_IR_STREAM, true);
|
||||||
|
|
||||||
|
|
||||||
outputMaps.resize( outputMapsTypesCount );
|
|
||||||
|
|
||||||
isContextOpened = true;
|
|
||||||
|
|
||||||
setProperty(CV_CAP_PROP_OPENNI_REGISTRATION, 1.0);
|
setProperty(CV_CAP_PROP_OPENNI_REGISTRATION, 1.0);
|
||||||
|
|
||||||
|
// default for Kinect2 camera
|
||||||
|
setProperty(CV_CAP_PROP_OPENNI2_MIRROR, 0.0);
|
||||||
|
|
||||||
|
isContextOpened = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
openni::Status CvCapture_OpenNI2::toggleStream(int stream, bool toggle)
|
CvCapture_OpenNI2::~CvCapture_OpenNI2()
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < streams.size(); ++i)
|
||||||
|
{
|
||||||
|
streamFrames[i].release();
|
||||||
|
streams[i].stop();
|
||||||
|
streams[i].destroy();
|
||||||
|
}
|
||||||
|
device.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CvCapture_OpenNI2::toggleStream(int stream, bool toggle)
|
||||||
{
|
{
|
||||||
openni::Status status;
|
openni::Status status;
|
||||||
|
|
||||||
// for logging
|
// for logging
|
||||||
static const char* stream_names[CV_MAX_NUM_STREAMS] = {
|
static const std::string stream_names[CV_MAX_NUM_STREAMS] = {
|
||||||
"depth",
|
"depth",
|
||||||
"color",
|
"color",
|
||||||
"IR"
|
"IR"
|
||||||
@ -280,140 +333,92 @@ openni::Status CvCapture_OpenNI2::toggleStream(int stream, bool toggle)
|
|||||||
{
|
{
|
||||||
// already opened
|
// already opened
|
||||||
if (streams[stream].isValid())
|
if (streams[stream].isValid())
|
||||||
return openni::STATUS_OK;
|
return;
|
||||||
|
|
||||||
// open stream
|
// open stream
|
||||||
status = streams[stream].create(device, stream_sensor_types[stream]);
|
status = streams[stream].create(device, stream_sensor_types[stream]);
|
||||||
if (status == openni::STATUS_OK)
|
if (status == openni::STATUS_OK)
|
||||||
{
|
{
|
||||||
// set video mode
|
// try to set up default stream mode (if available)
|
||||||
status = streams[stream].setVideoMode(defaultStreamOutputMode(stream)); // xn::DepthGenerator supports VGA only! (Jan 2011)
|
const openni::Array<openni::VideoMode>& vm = streams[stream].getSensorInfo().getSupportedVideoModes();
|
||||||
if (status != openni::STATUS_OK)
|
openni::VideoMode dm = defaultStreamOutputMode(stream);
|
||||||
|
for (int i = 0; i < vm.getSize(); i++)
|
||||||
{
|
{
|
||||||
CV_Error(CV_StsError, cv::format("CvCapture_OpenNI2::CvCapture_OpenNI2 : Couldn't set %s stream output mode: %s\n",
|
if (vm[i].getPixelFormat() == dm.getPixelFormat() &&
|
||||||
stream_names[stream],
|
vm[i].getResolutionX() == dm.getResolutionX() &&
|
||||||
openni::OpenNI::getExtendedError()));
|
vm[i].getResolutionY() == dm.getResolutionY() &&
|
||||||
streams[stream].destroy();
|
vm[i].getFps() == dm.getFps())
|
||||||
return status;
|
{
|
||||||
|
status = streams[stream].setVideoMode(defaultStreamOutputMode(stream));
|
||||||
|
if (status != openni::STATUS_OK)
|
||||||
|
{
|
||||||
|
streams[stream].destroy();
|
||||||
|
CV_Error(CV_StsError, std::string("OpenCVKinect2 : Couldn't set ") +
|
||||||
|
stream_names[stream] + std::string(" stream output mode: ") +
|
||||||
|
std::string(openni::OpenNI::getExtendedError()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// start stream
|
// start stream
|
||||||
status = streams[stream].start();
|
status = streams[stream].start();
|
||||||
if (status != openni::STATUS_OK)
|
if (status != openni::STATUS_OK)
|
||||||
{
|
{
|
||||||
CV_Error(CV_StsError, cv::format("CvCapture_OpenNI2::CvCapture_OpenNI2 : Couldn't start %s stream: %s\n",
|
|
||||||
stream_names[stream],
|
|
||||||
openni::OpenNI::getExtendedError()));
|
|
||||||
streams[stream].destroy();
|
streams[stream].destroy();
|
||||||
return status;
|
CV_Error(CV_StsError, std::string("CvCapture_OpenNI2::CvCapture_OpenNI2 : Couldn't start ") +
|
||||||
|
stream_names[stream] + std::string(" stream: ") +
|
||||||
|
std::string(openni::OpenNI::getExtendedError()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CV_Error(CV_StsError, cv::format("CvCapture_OpenNI2::CvCapture_OpenNI2 : Couldn't find %s stream:: %s\n",
|
CV_Error(CV_StsError, std::string("CvCapture_OpenNI2::CvCapture_OpenNI2 : Couldn't find ") +
|
||||||
stream_names[stream],
|
stream_names[stream] + " stream: " +
|
||||||
openni::OpenNI::getExtendedError()));
|
std::string(openni::OpenNI::getExtendedError()));
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (streams[stream].isValid()) // want to close stream
|
else if (streams[stream].isValid()) // want to close stream
|
||||||
{
|
{
|
||||||
streams[stream].stop();
|
//FIX for libfreenect2
|
||||||
streams[stream].destroy();
|
//which stops the whole device when stopping only one stream
|
||||||
}
|
|
||||||
|
|
||||||
return openni::STATUS_OK;
|
//streams[stream].stop();
|
||||||
|
//streams[stream].destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CvCapture_OpenNI2::CvCapture_OpenNI2(const char * filename)
|
|
||||||
{
|
|
||||||
openni::Status status;
|
|
||||||
|
|
||||||
isContextOpened = false;
|
void CvCapture_OpenNI2::readCamerasParams()
|
||||||
maxBufferSize = DEFAULT_MAX_BUFFER_SIZE;
|
|
||||||
isCircleBuffer = DEFAULT_IS_CIRCLE_BUFFER;
|
|
||||||
maxTimeDuration = DEFAULT_MAX_TIME_DURATION;
|
|
||||||
|
|
||||||
// Initialize and configure the context.
|
|
||||||
status = openni::OpenNI::initialize();
|
|
||||||
|
|
||||||
if (status != openni::STATUS_OK)
|
|
||||||
{
|
|
||||||
CV_Error(CV_StsError, cv::format("Failed to initialize:", openni::OpenNI::getExtendedError()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open file
|
|
||||||
status = device.open(filename);
|
|
||||||
if( status != openni::STATUS_OK )
|
|
||||||
{
|
|
||||||
CV_Error(CV_StsError, cv::format("CvCapture_OpenNI2::CvCapture_OpenNI2 : Failed to open input file (%s): %s\n", filename, openni::OpenNI::getExtendedError()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = openni::Status(toggleStream(CV_DEPTH_STREAM, true) | toggleStream(CV_COLOR_STREAM, true));
|
|
||||||
if (status != openni::STATUS_OK)
|
|
||||||
{
|
|
||||||
openni::OpenNI::shutdown();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !readCamerasParams() )
|
|
||||||
{
|
|
||||||
CV_Error(CV_StsError, cv::format("CvCapture_OpenNI2::CvCapture_OpenNI2 : Could not read cameras parameters\n"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
outputMaps.resize( outputMapsTypesCount );
|
|
||||||
|
|
||||||
isContextOpened = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
CvCapture_OpenNI2::~CvCapture_OpenNI2()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < CV_MAX_NUM_STREAMS; ++i)
|
|
||||||
{
|
|
||||||
streamFrames[i].release();
|
|
||||||
streams[i].stop();
|
|
||||||
streams[i].destroy();
|
|
||||||
}
|
|
||||||
device.close();
|
|
||||||
openni::OpenNI::shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CvCapture_OpenNI2::readCamerasParams()
|
|
||||||
{
|
{
|
||||||
double pixelSize = 0;
|
double pixelSize = 0;
|
||||||
if (streams[CV_DEPTH_STREAM].getProperty<double>(XN_STREAM_PROPERTY_ZERO_PLANE_PIXEL_SIZE, &pixelSize) != openni::STATUS_OK)
|
if (streams[CV_DEPTH_STREAM].getProperty<double>(XN_STREAM_PROPERTY_ZERO_PLANE_PIXEL_SIZE, &pixelSize) != openni::STATUS_OK)
|
||||||
{
|
{
|
||||||
CV_Error(CV_StsError, cv::format("CvCapture_OpenNI2::readCamerasParams : Could not read pixel size!\n"));
|
CV_Error(CV_StsError, "CvCapture_OpenNI2::readCamerasParams : Could not read pixel size!" +
|
||||||
return false;
|
std::string(openni::OpenNI::getExtendedError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// pixel size @ VGA = pixel size @ SXGA x 2
|
// pixel size @ VGA = pixel size @ SXGA x 2
|
||||||
pixelSize *= 2.0; // in mm
|
pixelSize *= 2.0; // in mm
|
||||||
|
|
||||||
// focal length of IR camera in pixels for VGA resolution
|
// focal length of IR camera in pixels for VGA resolution
|
||||||
int zeroPlanDistance; // in mm
|
unsigned long long zeroPlaneDistance; // in mm
|
||||||
if (streams[CV_DEPTH_STREAM].getProperty(XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE, &zeroPlanDistance) != openni::STATUS_OK)
|
if (streams[CV_DEPTH_STREAM].getProperty(XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE, &zeroPlaneDistance) != openni::STATUS_OK)
|
||||||
{
|
{
|
||||||
CV_Error(CV_StsError, cv::format("CvCapture_OpenNI2::readCamerasParams : Could not read virtual plane distance!\n"));
|
CV_Error(CV_StsError, "CvCapture_OpenNI2::readCamerasParams : Could not read virtual plane distance!" +
|
||||||
return false;
|
std::string(openni::OpenNI::getExtendedError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (streams[CV_DEPTH_STREAM].getProperty<double>(XN_STREAM_PROPERTY_EMITTER_DCMOS_DISTANCE, &baseline) != openni::STATUS_OK)
|
if (streams[CV_DEPTH_STREAM].getProperty<double>(XN_STREAM_PROPERTY_EMITTER_DCMOS_DISTANCE, &baseline) != openni::STATUS_OK)
|
||||||
{
|
{
|
||||||
CV_Error(CV_StsError, cv::format("CvCapture_OpenNI2::readCamerasParams : Could not read base line!\n"));
|
CV_Error(CV_StsError, "CvCapture_OpenNI2::readCamerasParams : Could not read base line!" +
|
||||||
return false;
|
std::string(openni::OpenNI::getExtendedError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// baseline from cm -> mm
|
// baseline from cm -> mm
|
||||||
baseline *= 10;
|
baseline *= 10;
|
||||||
|
|
||||||
// focal length from mm -> pixels (valid for 640x480)
|
// focal length from mm -> pixels (valid for 640x480)
|
||||||
depthFocalLength_VGA = (int)((double)zeroPlanDistance / (double)pixelSize);
|
depthFocalLength_VGA = (int)((double)zeroPlaneDistance / (double)pixelSize);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double CvCapture_OpenNI2::getProperty( int propIdx ) const
|
double CvCapture_OpenNI2::getProperty( int propIdx ) const
|
||||||
@ -500,7 +505,7 @@ double CvCapture_OpenNI2::getCommonProperty( int propIdx ) const
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default :
|
default :
|
||||||
CV_Error( CV_StsBadArg, cv::format("Such parameter (propIdx=%d) isn't supported for getting.\n", propIdx) );
|
CV_Error( CV_StsBadArg, cv::format("Such parameter (propIdx=%d) isn't supported for getting.", propIdx) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return propValue;
|
return propValue;
|
||||||
@ -525,14 +530,20 @@ bool CvCapture_OpenNI2::setCommonProperty( int propIdx, double propValue )
|
|||||||
// There is a set of properties that correspond to depth generator by default
|
// There is a set of properties that correspond to depth generator by default
|
||||||
// (is they are pass without particular generator flag).
|
// (is they are pass without particular generator flag).
|
||||||
case CV_CAP_PROP_OPENNI_REGISTRATION:
|
case CV_CAP_PROP_OPENNI_REGISTRATION:
|
||||||
isSet = setDepthGeneratorProperty( propIdx, propValue );
|
isSet = setDepthGeneratorProperty(propIdx, propValue);
|
||||||
break;
|
break;
|
||||||
case CV_CAP_PROP_OPENNI2_SYNC:
|
case CV_CAP_PROP_OPENNI2_SYNC:
|
||||||
isSet = device.setDepthColorSyncEnabled(propValue > 0.0) == openni::STATUS_OK;
|
isSet = device.setDepthColorSyncEnabled(propValue > 0.0) == openni::STATUS_OK;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CV_CAP_PROP_FRAME_WIDTH:
|
||||||
|
case CV_CAP_PROP_FRAME_HEIGHT:
|
||||||
|
case CV_CAP_PROP_AUTOFOCUS:
|
||||||
|
isSet = false;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
CV_Error( CV_StsBadArg, cv::format("Such parameter (propIdx=%d) isn't supported for setting.\n", propIdx) );
|
CV_Error(CV_StsBadArg, cv::format("Such parameter (propIdx=%d) isn't supported for setting.", propIdx));
|
||||||
}
|
}
|
||||||
|
|
||||||
return isSet;
|
return isSet;
|
||||||
@ -565,9 +576,13 @@ double CvCapture_OpenNI2::getDepthGeneratorProperty( int propIdx ) const
|
|||||||
propValue = streams[CV_DEPTH_STREAM].getMaxPixelValue();
|
propValue = streams[CV_DEPTH_STREAM].getMaxPixelValue();
|
||||||
break;
|
break;
|
||||||
case CV_CAP_PROP_OPENNI_BASELINE :
|
case CV_CAP_PROP_OPENNI_BASELINE :
|
||||||
|
if(baseline <= 0)
|
||||||
|
const_cast<CvCapture_OpenNI2*>(this)->readCamerasParams();
|
||||||
propValue = baseline;
|
propValue = baseline;
|
||||||
break;
|
break;
|
||||||
case CV_CAP_PROP_OPENNI_FOCAL_LENGTH :
|
case CV_CAP_PROP_OPENNI_FOCAL_LENGTH :
|
||||||
|
if(depthFocalLength_VGA <= 0)
|
||||||
|
const_cast<CvCapture_OpenNI2*>(this)->readCamerasParams();
|
||||||
propValue = (double)depthFocalLength_VGA;
|
propValue = (double)depthFocalLength_VGA;
|
||||||
break;
|
break;
|
||||||
case CV_CAP_PROP_OPENNI_REGISTRATION :
|
case CV_CAP_PROP_OPENNI_REGISTRATION :
|
||||||
@ -580,7 +595,7 @@ double CvCapture_OpenNI2::getDepthGeneratorProperty( int propIdx ) const
|
|||||||
propValue = streamFrames[CV_DEPTH_STREAM].getFrameIndex();
|
propValue = streamFrames[CV_DEPTH_STREAM].getFrameIndex();
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
CV_Error( CV_StsBadArg, cv::format("Depth generator does not support such parameter (propIdx=%d) for getting.\n", propIdx) );
|
CV_Error( CV_StsBadArg, cv::format("Depth generator does not support such parameter (propIdx=%d) for getting.", propIdx) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return propValue;
|
return propValue;
|
||||||
@ -594,7 +609,10 @@ bool CvCapture_OpenNI2::setDepthGeneratorProperty( int propIdx, double propValue
|
|||||||
{
|
{
|
||||||
case CV_CAP_PROP_OPENNI_GENERATOR_PRESENT:
|
case CV_CAP_PROP_OPENNI_GENERATOR_PRESENT:
|
||||||
if (isContextOpened)
|
if (isContextOpened)
|
||||||
isSet = toggleStream(CV_DEPTH_STREAM, propValue > 0.0) == openni::STATUS_OK;
|
{
|
||||||
|
toggleStream(CV_DEPTH_STREAM, propValue > 0.0);
|
||||||
|
isSet = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case CV_CAP_PROP_OPENNI_REGISTRATION:
|
case CV_CAP_PROP_OPENNI_REGISTRATION:
|
||||||
{
|
{
|
||||||
@ -612,12 +630,13 @@ bool CvCapture_OpenNI2::setDepthGeneratorProperty( int propIdx, double propValue
|
|||||||
{
|
{
|
||||||
openni::Status status = device.setImageRegistrationMode(mode);
|
openni::Status status = device.setImageRegistrationMode(mode);
|
||||||
if( status != openni::STATUS_OK )
|
if( status != openni::STATUS_OK )
|
||||||
CV_Error(CV_StsError, cv::format("CvCapture_OpenNI2::setDepthGeneratorProperty : %s\n", openni::OpenNI::getExtendedError()));
|
CV_Error(CV_StsError, std::string("CvCapture_OpenNI2::setDepthGeneratorProperty: ") +
|
||||||
|
std::string(openni::OpenNI::getExtendedError()));
|
||||||
else
|
else
|
||||||
isSet = true;
|
isSet = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CV_Error(CV_StsError, cv::format("CvCapture_OpenNI2::setDepthGeneratorProperty : Unsupported viewpoint.\n"));
|
CV_Error(CV_StsError, "CvCapture_OpenNI2::setDepthGeneratorProperty: Unsupported viewpoint.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
isSet = true;
|
isSet = true;
|
||||||
@ -627,14 +646,15 @@ bool CvCapture_OpenNI2::setDepthGeneratorProperty( int propIdx, double propValue
|
|||||||
{
|
{
|
||||||
openni::Status status = device.setImageRegistrationMode(openni::IMAGE_REGISTRATION_OFF);
|
openni::Status status = device.setImageRegistrationMode(openni::IMAGE_REGISTRATION_OFF);
|
||||||
if( status != openni::STATUS_OK )
|
if( status != openni::STATUS_OK )
|
||||||
CV_Error(CV_StsError, cv::format("CvCapture_OpenNI2::setDepthGeneratorProperty : %s\n", openni::OpenNI::getExtendedError()));
|
CV_Error(CV_StsError, std::string("CvCapture_OpenNI2::setDepthGeneratorProperty: ") +
|
||||||
|
std::string(openni::OpenNI::getExtendedError()));
|
||||||
else
|
else
|
||||||
isSet = true;
|
isSet = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
CV_Error( CV_StsBadArg, cv::format("Depth generator does not support such parameter (propIdx=%d) for setting.\n", propIdx) );
|
CV_Error( CV_StsBadArg, cv::format("Depth generator does not support such parameter (propIdx=%d) for setting.", propIdx) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return isSet;
|
return isSet;
|
||||||
@ -668,7 +688,7 @@ double CvCapture_OpenNI2::getImageGeneratorProperty( int propIdx ) const
|
|||||||
propValue = (double)streamFrames[CV_COLOR_STREAM].getFrameIndex();
|
propValue = (double)streamFrames[CV_COLOR_STREAM].getFrameIndex();
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
CV_Error( CV_StsBadArg, cv::format("Image generator does not support such parameter (propIdx=%d) for getting.\n", propIdx) );
|
CV_Error( CV_StsBadArg, cv::format("Image generator does not support such parameter (propIdx=%d) for getting.", propIdx) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return propValue;
|
return propValue;
|
||||||
@ -682,7 +702,10 @@ bool CvCapture_OpenNI2::setImageGeneratorProperty(int propIdx, double propValue)
|
|||||||
{
|
{
|
||||||
case CV_CAP_PROP_OPENNI_GENERATOR_PRESENT:
|
case CV_CAP_PROP_OPENNI_GENERATOR_PRESENT:
|
||||||
if (isContextOpened)
|
if (isContextOpened)
|
||||||
isSet = toggleStream(CV_COLOR_STREAM, propValue > 0.0) == openni::STATUS_OK;
|
{
|
||||||
|
toggleStream(CV_COLOR_STREAM, propValue > 0.0);
|
||||||
|
isSet = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case CV_CAP_PROP_OPENNI_OUTPUT_MODE :
|
case CV_CAP_PROP_OPENNI_OUTPUT_MODE :
|
||||||
{
|
{
|
||||||
@ -713,18 +736,19 @@ bool CvCapture_OpenNI2::setImageGeneratorProperty(int propIdx, double propValue)
|
|||||||
mode.setFps(60);
|
mode.setFps(60);
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
CV_Error( CV_StsBadArg, "Unsupported image generator output mode.\n");
|
CV_Error( CV_StsBadArg, "Unsupported image generator output mode.");
|
||||||
}
|
}
|
||||||
|
|
||||||
openni::Status status = streams[CV_COLOR_STREAM].setVideoMode( mode );
|
openni::Status status = streams[CV_COLOR_STREAM].setVideoMode( mode );
|
||||||
if( status != openni::STATUS_OK )
|
if( status != openni::STATUS_OK )
|
||||||
CV_Error(CV_StsError, cv::format("CvCapture_OpenNI2::setImageGeneratorProperty : %s\n", openni::OpenNI::getExtendedError()));
|
CV_Error(CV_StsError, std::string("CvCapture_OpenNI2::setImageGeneratorProperty: ") +
|
||||||
|
std::string(openni::OpenNI::getExtendedError()));
|
||||||
else
|
else
|
||||||
isSet = true;
|
isSet = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
CV_Error( CV_StsBadArg, cv::format("Image generator does not support such parameter (propIdx=%d) for setting.\n", propIdx) );
|
CV_Error( CV_StsBadArg, cv::format("Image generator does not support such parameter (propIdx=%d) for setting.", propIdx) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return isSet;
|
return isSet;
|
||||||
@ -758,7 +782,7 @@ double CvCapture_OpenNI2::getIrGeneratorProperty(int propIdx) const
|
|||||||
propValue = (double)streamFrames[CV_IR_STREAM].getFrameIndex();
|
propValue = (double)streamFrames[CV_IR_STREAM].getFrameIndex();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
CV_Error(CV_StsBadArg, cv::format("Image generator does not support such parameter (propIdx=%d) for getting.\n", propIdx));
|
CV_Error(CV_StsBadArg, cv::format("Image generator does not support such parameter (propIdx=%d) for getting.", propIdx));
|
||||||
}
|
}
|
||||||
|
|
||||||
return propValue;
|
return propValue;
|
||||||
@ -772,7 +796,10 @@ bool CvCapture_OpenNI2::setIrGeneratorProperty(int propIdx, double propValue)
|
|||||||
{
|
{
|
||||||
case CV_CAP_PROP_OPENNI_GENERATOR_PRESENT:
|
case CV_CAP_PROP_OPENNI_GENERATOR_PRESENT:
|
||||||
if (isContextOpened)
|
if (isContextOpened)
|
||||||
isSet = toggleStream(CV_IR_STREAM, propValue > 0.0) == openni::STATUS_OK;
|
{
|
||||||
|
toggleStream(CV_IR_STREAM, propValue > 0.0);
|
||||||
|
isSet = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case CV_CAP_PROP_OPENNI_OUTPUT_MODE:
|
case CV_CAP_PROP_OPENNI_OUTPUT_MODE:
|
||||||
{
|
{
|
||||||
@ -803,18 +830,19 @@ bool CvCapture_OpenNI2::setIrGeneratorProperty(int propIdx, double propValue)
|
|||||||
mode.setFps(60);
|
mode.setFps(60);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
CV_Error(CV_StsBadArg, "Unsupported image generator output mode.\n");
|
CV_Error(CV_StsBadArg, "Unsupported image generator output mode.");
|
||||||
}
|
}
|
||||||
|
|
||||||
openni::Status status = streams[CV_IR_STREAM].setVideoMode(mode);
|
openni::Status status = streams[CV_IR_STREAM].setVideoMode(mode);
|
||||||
if (status != openni::STATUS_OK)
|
if (status != openni::STATUS_OK)
|
||||||
CV_Error(CV_StsError, cv::format("CvCapture_OpenNI2::setImageGeneratorProperty : %s\n", openni::OpenNI::getExtendedError()));
|
CV_Error(CV_StsError, std::string("CvCapture_OpenNI2::setImageGeneratorProperty: ") +
|
||||||
|
std::string(openni::OpenNI::getExtendedError()));
|
||||||
else
|
else
|
||||||
isSet = true;
|
isSet = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
CV_Error(CV_StsBadArg, cv::format("Image generator does not support such parameter (propIdx=%d) for setting.\n", propIdx));
|
CV_Error(CV_StsBadArg, cv::format("Image generator does not support such parameter (propIdx=%d) for setting.", propIdx));
|
||||||
}
|
}
|
||||||
|
|
||||||
return isSet;
|
return isSet;
|
||||||
@ -931,10 +959,12 @@ IplImage* CvCapture_OpenNI2::retrieveDisparityMap()
|
|||||||
if (!streamFrames[CV_DEPTH_STREAM].isValid())
|
if (!streamFrames[CV_DEPTH_STREAM].isValid())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
readCamerasParams();
|
||||||
|
|
||||||
cv::Mat disp32;
|
cv::Mat disp32;
|
||||||
computeDisparity_32F(streamFrames[CV_DEPTH_STREAM], disp32, baseline, depthFocalLength_VGA, noSampleValue, shadowValue);
|
computeDisparity_32F(streamFrames[CV_DEPTH_STREAM], disp32, baseline, depthFocalLength_VGA, noSampleValue, shadowValue);
|
||||||
|
|
||||||
disp32.convertTo( outputMaps[CV_CAP_OPENNI_DISPARITY_MAP].mat, CV_8UC1 );
|
disp32.convertTo(outputMaps[CV_CAP_OPENNI_DISPARITY_MAP].mat, CV_8UC1);
|
||||||
|
|
||||||
return outputMaps[CV_CAP_OPENNI_DISPARITY_MAP].getIplImagePtr();
|
return outputMaps[CV_CAP_OPENNI_DISPARITY_MAP].getIplImagePtr();
|
||||||
}
|
}
|
||||||
@ -944,6 +974,8 @@ IplImage* CvCapture_OpenNI2::retrieveDisparityMap_32F()
|
|||||||
if (!streamFrames[CV_DEPTH_STREAM].isValid())
|
if (!streamFrames[CV_DEPTH_STREAM].isValid())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
readCamerasParams();
|
||||||
|
|
||||||
computeDisparity_32F(streamFrames[CV_DEPTH_STREAM], outputMaps[CV_CAP_OPENNI_DISPARITY_MAP_32F].mat, baseline, depthFocalLength_VGA, noSampleValue, shadowValue);
|
computeDisparity_32F(streamFrames[CV_DEPTH_STREAM], outputMaps[CV_CAP_OPENNI_DISPARITY_MAP_32F].mat, baseline, depthFocalLength_VGA, noSampleValue, shadowValue);
|
||||||
|
|
||||||
return outputMaps[CV_CAP_OPENNI_DISPARITY_MAP_32F].getIplImagePtr();
|
return outputMaps[CV_CAP_OPENNI_DISPARITY_MAP_32F].getIplImagePtr();
|
||||||
@ -966,7 +998,7 @@ inline void getBGRImageFromMetaData( const openni::VideoFrameRef& imageMetaData,
|
|||||||
{
|
{
|
||||||
cv::Mat bufferImage;
|
cv::Mat bufferImage;
|
||||||
if( imageMetaData.getVideoMode().getPixelFormat() != openni::PIXEL_FORMAT_RGB888 )
|
if( imageMetaData.getVideoMode().getPixelFormat() != openni::PIXEL_FORMAT_RGB888 )
|
||||||
CV_Error( CV_StsUnsupportedFormat, "Unsupported format of grabbed image\n" );
|
CV_Error( CV_StsUnsupportedFormat, "Unsupported format of grabbed image." );
|
||||||
|
|
||||||
bgrImage.create(imageMetaData.getHeight(), imageMetaData.getWidth(), CV_8UC3);
|
bgrImage.create(imageMetaData.getHeight(), imageMetaData.getWidth(), CV_8UC3);
|
||||||
bufferImage.create(imageMetaData.getHeight(), imageMetaData.getWidth(), CV_8UC3);
|
bufferImage.create(imageMetaData.getHeight(), imageMetaData.getWidth(), CV_8UC3);
|
||||||
@ -989,7 +1021,7 @@ inline void getGrayImageFromMetaData(const openni::VideoFrameRef& imageMetaData,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CV_Error(CV_StsUnsupportedFormat, "Unsupported format of grabbed image\n");
|
CV_Error(CV_StsUnsupportedFormat, "Unsupported format of grabbed image.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user