简体   繁体   English

Kinect V2读取深度问题

[英]Kinect V2 read Depth issue

The following C++ code is given which continuously fetches the latest frame from a Kinect 2. 给出了以下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;
    }
}

In fact, if I connect Kinect to my laptop or not, the output is no changing and it is: "not found". 实际上,无论我是否将Kinect连接到笔记本电脑,输出都不会改变,而是:“未找到”。 When I connect Kinect and run the program, the lights of Kinect turns on. 当我连接Kinect并运行程序时,Kinect的灯会亮起。 In some ready codes, Kinect works correctly. 在某些就绪代码中,Kinect可以正常工作。 Where is the problem? 问题出在哪儿?

You should check out the returned error code for AcquireLatestFrame , maybe it can tell you what's the problem. 您应该检查出AcquireLatestFrame返回的错误代码,也许它可以告诉您问题出在哪里。

Here's a tip: maybe, when you call AcquireLatestFrame , the frame is not available yet. 提示:也许,当您调用AcquireLatestFrame ,该框架尚不可用。 So put this call into a loop, sooner or later the frame will be available. 因此,将此调用放入一个循环中,迟早该框架将可用。

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

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