无法在C ++中获取Color框架 [英] Unable to get Color frame in C++

查看:60
本文介绍了无法在C ++中获取Color框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Folks,


我正在尝试编写一个非常简单的C ++应用程序,通过轮询从Kinect摄像头获取彩色图像。  我有以下代码:


 

 
#include< Windows.h>
#include " MSR_NuiApi.h"

#include< iostream>


int main()
{
static const int WAIT_TIME = 100;

static const int NUM_FRAMES = 2;

DWORD kflags = NUI_INITIALIZE_FLAG_USES_COLOR;

HRESULT init = NuiInitialize(kflags);
if (FAILED(init))
{
std :: cout<< "Kinect初始化失败。"<<的std :: ENDL;
return -1;
}

HANDLE colorImageStream;
HRESULT streamColorOpen = NuiImageStreamOpen(
NUI_IMAGE_TYPE_COLOR,
NUI_IMAGE_RESOLUTION_640x480,
0,
NUM_FRAMES,
INVALID_HANDLE_VALUE,
& colorImageStream
);

if (FAILED(streamColorOpen))
{
std :: cout<< "无法打开颜色流。"<<的std :: ENDL;
return -1;
}

const NUI_IMAGE_FRAME * colorFrame = NULL;
HRESULT color = NuiImageStreamGetNextFrame(
colorImageStream,
WAIT_TIME,
& colorFrame
);

if (FAILED(color))
{
std :: cout<< "无法获取彩色框架。"<<的std :: ENDL;
return -1;
}

NuiImageStreamReleaseFrame(colorImageStream,colorFrame);

NuiShutdown();
return 0;
}

解决方案

即使你将WAIT_TIME增加到更大,会发生这种情况吗?平均而言,帧之间需要大约30ms,但第一帧可能需要更长的时间才能到达。出于测试目的,尝试10秒等待,然后
让我们知道这是否也不起作用。


等待时间越短也应该工作,但是你需要只处理E_NUI_FRAME_NO_DATA作为预期的可能失败,并在这种情况下再次循环以尝试再次获取数据,如果您正在进行轮询。


Eddy


Hi Folks,

I am trying to write a very simple C++ app with polling to get color images from the Kinect camera.  I have the following code:

 

#include <Windows.h>
#include "MSR_NuiApi.h"

#include <iostream>


int main()
{
	static const int WAIT_TIME = 100;

	static const int NUM_FRAMES = 2;

	DWORD kflags = NUI_INITIALIZE_FLAG_USES_COLOR;

	HRESULT init = NuiInitialize(kflags);
	if (FAILED(init))
	{
		std::cout << "Kinect initialization failed." << std::endl;
		return -1;
	}

	HANDLE colorImageStream;
	HRESULT streamColorOpen = NuiImageStreamOpen(
		NUI_IMAGE_TYPE_COLOR,
		NUI_IMAGE_RESOLUTION_640x480,
		0,
		NUM_FRAMES,
		INVALID_HANDLE_VALUE,
		&colorImageStream
	);

	if (FAILED(streamColorOpen))
	{
		std::cout << "Unable to open color stream." << std::endl;
		return -1;
	}

	const NUI_IMAGE_FRAME * colorFrame = NULL;
	HRESULT color = NuiImageStreamGetNextFrame(
		colorImageStream,
		WAIT_TIME,
		&colorFrame
	);

	if (FAILED(color))
	{
		std::cout << "Unable to get Color frame." << std::endl;
		return -1;
	}
	
	NuiImageStreamReleaseFrame(colorImageStream, colorFrame);

	NuiShutdown();
	return 0;
}

解决方案

Does this happen even if you increase your WAIT_TIME to be bigger? In average, it should take approximately 30ms between frames, but the first frame might take a little longer to arrive. For testing purposes, try something like a 10 second wait, and then let us know if that doesn't work either.

Having the shorter wait should work too, but you need to just handle E_NUI_FRAME_NO_DATA as an expected possible failure and just loop again to try to get data again in that case, if you're doing polling.

Eddy


这篇关于无法在C ++中获取Color框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆