想要打开奥比中光的双目摄像头的深度图像,按照官网环境配置完全一样,但是一运行程序就报错,具体如下
这是配置的环境与代码错误,源程序摘与一位博客主的原创代码
#include<opencv2/opencv.hpp>
#include<OpenNI.h>
#include <stdio.h>
using namespace openni;
int main(int argc,char ** argv[])
{
int m = 2;
//初始化OpenNI SDK
OpenNI::initialize();
//打开设备
Device device;
device.open(ANY_DEVICE);
//创建深度流
VideoStream depthStream;
depthStream.create(device, SENSOR_DEPTH);
//配置深度流的模式
VideoMode depthMode;
depthMode.setResolution(640, 480);
depthMode.setPixelFormat(PIXEL_FORMAT_DEPTH_1_MM);
depthMode.setFps(30);
depthStream.setVideoMode(depthMode);
//打开深度流
depthStream.start();
VideoFrameRef frame;
while (true)
{
VideoStream* pstream = &depthStream;
int changedStreamDummy;
//等待一帧
Status rc = OpenNI::waitForAnyStream(&pstream, 1, &changedStreamDummy, 100);
if (rc != STATUS_OK)
{
continue;
}
//获取深度帧数据
rc = depthStream.readFrame(&frame);
if (rc == STATUS_OK)
{
auto depth = frame.getData();
auto depthWidth = frame.getWidth();
auto depthHeight = frame.getHeight();
//处理并渲染深度帧数据
cv::Mat rawMat(depthHeight, depthWidth, CV_16UC1, (void*)depth);
cv::Mat depthMat;
rawMat.convertTo(depthMat, CV_8UC1);
cv::imshow("Depth Viewer", depthMat);
}
//按ESC退出
int key = cv::waitKey(100);
if (key == 27)
break;
}
depthStream.stop();
depthStream.destroy();
device.close();
OpenNI::shutdown();
return 0;
},
想请大佬们帮忙解决麻烦,困扰小白好久了,谢谢!