与OpenNI兼容的深度传感器(Kinect, XtionPRO,...)被VideoCapture类支持, 深度图像,RGB图像和其他种类的输出可以使用类似于VideoCapture的接口retrieve。为了使用OpenCV的深度传感器,你需要完成下面的步骤:
1.安装OpenNI 库(从http://www.openni.org/downloadfiles下载)和针对OpenNI的PrimeSensor组件(从https://github.com/avin2/SensorKinect 下载)。安装需要按照指导放在默认的文件夹下。
2. 在CMake中设置WITH_OPENNI标志,用OpenNI配置OpenCV。如果没有发现PrimeSensor 组件,但发现OpenNI在安装文件下(查看CMake log 下状态OpenNI PrimeSensor Modules),OpenCV将与OpenNI库一起编译(查看CMake log下状态OpenNI)。没有PrimeSensor module OpenCV 将和OpenNI库一起成功编译,但是VideoCapture对象却无法从Kinect传感器抓取图像
3.编译OpenCV
VideoCapture 可以retrieve下列数据:
1.从depth generator取数据
OPENNI_DEPTH_MAP - depth values in mm(CV_16UC1)
OPENNI_POINT_CLOUD_MAP- XYZ in meters(CV_32FC3)
OPENNI_DISPARITY_MAP - disparity in pixels(CV_8UC1)
OPENNI_DISPARITY_MAP_32F - disparity in pixels (CV_32FC1)
OPENNI_VALID_DEPTH_MASK - mask of valid pixels (not ocluded, not shaded etc.) (CV_8UC1)
2.从RGB image generator得到的数据
OPENNI_BGR_IMAGE - color image (CV_8UC3)
OPENNI_GRAY_IMAGE - gray image (CV_8UC1)
为了得到从深度传感器得到深度图像,使用VideoCapture::operator >>, 例如
for(;;)
{
Mat depthMap;
capture >> depthMap;
if( waitKey( 30 ) >= 0 )
break;
}
得到几幅数据图使用VideoCapture::grab和VideoCapture::retrieve,例如
VideoCapture capture(0); // or CV_CAP_OPENNI
for(;;)
{
Mat depthMap;
Mat rgbImage
capture.grab();
capture.retrieve( depthMap, OPENNI_DEPTH_MAP );
capture.retrieve( bgrImage, OPENNI_BGR_IMAGE );
if( waitKey( 30 ) >= 0 )
break;
}
设置和读取传感器的特性,使用VideoCapture::set 和 VideoCapture::get,例如
VideoCapture capture( CV_CAP_OPENNI );
capture.set( CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE, CV_CAP_OPENNI_VGA_30HZ );
cout << "FPS " << capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FPS ) << endl;
由于有两种传感器数据生成器被支持,有对应的两个标志
CV_CAP_OPENNI_IMAGE_GENERATOR –访问the image generator 属性的标志.
CV_CAP_OPENNI_DEPTH_GENERATOR – 访问 the depth generator 属性的标志. 默认设置
一些深度传感器(例如XtionPRO)没有image generator,可以通CV_CAP_OPENNI_IMAGE_GENERATOR_PRESENT属性查看。
bool isImageGeneratorPresent = capture.get( CV_CAP_PROP_OPENNI_IMAGE_GENERATOR_PRESENT ) != 0; // or == 1
定义生成器类型 的标志必须和特定的生成器属性相一致,下列相机的特性通过OpenNI接口被支持:
image generatior:
CV_CAP_PROP_OPENNI_OUTPUT_MODE
三种输出模式被支持: CV_CAP_OPENNI_VGA_30HZ 缺省(VGA resolution with 30 FPS),
CV_CAP_OPENNI_SXGA_15HZ ( SXGA resolution with 15 FPS)
and CV_CAP_OPENNI_SXGA_30HZ (SXGA resolution with 30 FPS, 被XtionPRO Live支持);
深度传感器
CV_CAP_PROP_OPENNI_REGISTRATION – 表示深度图像投影到image map
适用的新特性
– CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH – Kinect支持的最大深度 mm.
– CV_CAP_PROP_OPENNI_BASELINE – 基线值 mm.
– CV_CAP_PROP_OPENNI_FOCAL_LENGTH –焦距.
– CV_CAP_PROP_FRAME_WIDTH – 帧宽.
– CV_CAP_PROP_FRAME_HEIGHT – 帧高.
– CV_CAP_PROP_FPS – 帧速.
组合generator type+property定义成一个单个标志
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
CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION = CV_CAP_OPENNI_DEPTH_GENERATOR +
CV_CAP_PROP_OPENNI_REGISTRATION
http://blog.csdn.net/dragonfly90/article/details/8025558