繁体   English   中英

Kinect V2读取深度问题

[英]Kinect V2 read Depth issue

给出了以下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 ,该框架尚不可用。 因此,将此调用放入一个循环中,迟早该框架将可用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM