###一、openni2使用摄像头获取图像步骤:
1.openni初始化
2.openni打开设备
3.创建数据流并设置数据流模式
二、转化点云步骤
1.使用openni从数据流读取一帧图像
2.使用openni从图像读取像素数据
3.处理数据,将结果存入点云
三、示例代码
#include <iostream>
#include <OpenNI.h>
#include <pcl/common/common_headers.h> // for pcl::PointCloud
#include <pcl/visualization/pcl_visualizer.h>
openni::Device mDevice;
openni::VideoStream mColorStream;
openni::VideoStream mDepthStream;
bool init(){
// Initial OpenNI
if(openni::OpenNI::initialize() != openni::STATUS_OK){
std::cerr << "OpenNI Initial Error: " << openni::OpenNI::getExtendedError() << std::endl;
return false;
}
// Open Device
if(mDevice.open(openni::ANY_DEVICE) != openni::STATUS_OK) {
std::cerr << "Can't Open Device: " << openni::OpenNI::getExtendedError() << std::endl;
return false;
}
return true;
}
bool createColorStream() {
if(mDevice.hasSensor(openni::SENSOR_COLOR)) {
if(mColorStream.create(mDevice, openni::SENSOR_COLOR) == openni::STATUS_OK) {
// set video mode
openni::VideoMode mMode;
mMode.setResolution(640, 480);
mMode.setFps(30);
mMode.setP