【发布时间】:2015-06-10 22:18:42
【问题描述】:
我有一个 kinect 将数据流式传输到 cv::Mat。我正在尝试运行一些使用 OpenNI 的示例代码。
我能否以某种方式将我的 Mat 转换为 OpenNI 格式的图像?
我只需要深度图,和OpenNI打了半天,已经放弃安装了。
我正在使用 OpenCV 3、Visual Studio 2013、Kinect v2 for Windows。
相关代码为:
void CDifodoCamera::loadFrame()
{
//Read the newest frame
openni::VideoFrameRef framed; //I assume I need to replace this with my Mat...
depth_ch.readFrame(&framed);
const int height = framed.getHeight();
const int width = framed.getWidth();
//Store the depth values
const openni::DepthPixel* pDepthRow = (const openni::DepthPixel*)framed.getData();
int rowSize = framed.getStrideInBytes() / sizeof(openni::DepthPixel);
for (int yc = height-1; yc >= 0; --yc)
{
const openni::DepthPixel* pDepth = pDepthRow;
for (int xc = width-1; xc >= 0; --xc, ++pDepth)
{
if (*pDepth < 4500.f)
depth_wf(yc,xc) = 0.001f*(*pDepth);
else
depth_wf(yc,xc) = 0.f;
}
pDepthRow += rowSize;
}
}
【问题讨论】:
-
为什么需要openni?我的意思是,这个示例代码可以重写为直接使用 opencv 图像而不用 openni....
-
更好!我只是不确定如何获得一个垫子。我怎样才能重写它以使其工作?感谢您的宝贵时间。