Kinect V2 已閱讀深度問題

Kinect V2 read Depth issue

本文关键字:深度 V2 Kinect      更新时间:2023-10-16

给出了以下C++代码,该代码不断从 Kinect 2 获取最新帧。

#include <Kinect.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <Windows.h>
#include <iostream>
using namespace std;
const int width = 512;
const int height = 424;
const int colorwidth = 1920;
const int colorheight = 1080;
IDepthFrameReader* reader;     // Kinect depth data source
IKinectSensor* sensor = nullptr;
int main(int argc, char* argv[]) {
if (FAILED(GetDefaultKinectSensor(&sensor))) {
return 19;
}
if (sensor) {
sensor->Open();
IDepthFrameSource* framesource = NULL;
sensor->get_DepthFrameSource(&framesource);
framesource->OpenReader(&reader);
if (framesource) {
framesource->Release();
framesource = NULL;
}
IDepthFrame* frame = NULL;
if (SUCCEEDED(reader->AcquireLatestFrame(&frame))) {
cout << "not bad";
getchar();
return 100;
}
else{
cout << "not found";
getchar();
return 23;
}
}
else {
return -1;
}
}

实际上,如果我是否将Kinect连接到笔记本电脑,输出不会改变,并且是:"未找到"。當我連接 Kinect 並運行程序時,Kinect 的燈會亮起。在某些现成的代码中,Kinect 可以正常工作。问题出在哪里?

您应该查看返回的错误代码以获取AcquireLatestFrame,也许它可以告诉您问题所在。

这里有一个提示:也许,当你打电话给AcquireLatestFrame时,框架还不可用。所以把这个调用放进一个循环中,迟早帧会可用。