更改openni2上的解决方案不工作 [英] Change resolution on openni2 not working

查看:555
本文介绍了更改openni2上的解决方案不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在640x480读取深度帧。

我使用Windows 8.1 64位,openni2 32位,kinect:PSMP05000,PSCM04900(PrimeSense)



我从这里获取代码引用:

无法设置VGA分辨率

简单阅读



结合使用此代码:

主要。 cpp

OniSampleUtilities.h

SimpleRead.vcxproj

应为编译如果您从这里安装openni2 32位:

OpeniNI 2

  #includeiostream
#includeOpenNI.h
#includeOniSampleUtilities.h

#define SAMPLE_READ_WAIT_TIMEOUT 2000 // 2000ms

使用命名空间openni;
using namespace std;

int main()
{
状态rc = OpenNI :: initialize();
if(rc!= STATUS_OK)
{
cout< Initialize failed:<< endl<< OpenNI :: getExtendedError()<< endl;
return 1;
}

设备设备;
rc = device.open(ANY_DEVICE);
if(rc!= STATUS_OK)
{
cout< 无法打开设备< endl<< OpenNI :: getExtendedError()<< endl;
return 2;
}

VideoStream depth;

if(device.getSensorInfo(SENSOR_DEPTH)!= NULL)
{
rc = depth.create(device,SENSOR_DEPTH);
if(rc!= STATUS_OK)
{
cout< 无法创建深度流< endl<< OpenNI :: getExtendedError()<< endl;
return 3;
}
}

rc = depth.start();
if(rc!= STATUS_OK)
{
cout< 无法启动深度流< endl<< OpenNI :: getExtendedError()<< endl;
return 4;
}

VideoFrameRef框架;

//设置分辨率
//深度模式
cout<< 深度模式< endl;
const openni :: SensorInfo * sinfo = device.getSensorInfo(openni :: SENSOR_DEPTH); // select index = 4 640x480,30 fps,1mm
const openni :: Array< openni :: VideoMode>& modesDepth = sinfo-> getSupportedVideoModes();
for(int i = 0; i< modesDepth.getSize(); i ++){
printf(%i:%ix%i,%i fps,%i format\\\
,i ,modesDepth [i] .getResolutionX(),modesDepth [i] .getResolutionY(),
modesDepth [i] .getFps(),modesDepth [i] .getPixelFormat() // PIXEL_FORMAT_DEPTH_1_MM = 100,PIXEL_FORMAT_DEPTH_100_UM
}
rc = depth.setVideoMode(modesDepth [0]);
if(openni :: STATUS_OK!= rc)
{
cout< error:depth fromat not supprted ...< endl;
}
system(pause);
while(!wasKeyboardHit())
{
int changedStreamDummy;
VideoStream * pStream =& depth;
rc = OpenNI :: waitForAnyStream(& pStream,1,& changedStreamDummy,SAMPLE_READ_WAIT_TIMEOUT);
if(rc!= STATUS_OK)
{
cout< 等待失败!(超时为 continue;
}

rc = depth.readFrame(& frame);
if(rc!= STATUS_OK)
{
cout< 读失败! << endl<< OpenNI :: getExtendedError()<< endl;
continue;
}

if(frame.getVideoMode()。getPixelFormat()!= PIXEL_FORMAT_DEPTH_1_MM&& amp; frame.getVideoMode()。getPixelFormat()!= PIXEL_FORMAT_DEPTH_100_UM)
{
cout<< 意外帧格式< endl;
continue;
}

DepthPixel * pDepth =(DepthPixel *)frame.getData();

int middleIndex =(frame.getHeight()+ 1)* frame.getWidth()/ 2;

printf([%08llu]%8d \\\
,(long long)frame.getTimestamp(),pDepth [middleIndex]);
}

depth.stop();
depth.destroy();
device.close();
OpenNI :: shutdown();

return 0;
}

有6种操作模式:

  0:320x240,30 fps,100格式
1:320x240,30 fps,101格式
2:320x240,60 fps,100格式
3:320x240,60 fps,101格式
4:640x480,30 fps,100格式
5:640x480,30 fps,101格式

它只能从modes = 0-3读取。

在模式4,5,我得到超时。

如何在640x480读取深度帧?



感谢您的帮助,

Tal。



====================================== ============

新信息:



我也使用这一行,我得到相同的结果:

  const openni :: SensorInfo * sinfo =&(depth.getSensorInfo()); 


此行从不在任何模式下执行:

  cout<< error:depth fromat not supprted ...< endl; 


在模式4,5下,我总是得到此行执行:

  cout<< 等待失败(超时为  


我想也许这是openni2的错误。

在openni1,我可以在同一台计算机,操作系统和设备上读取640x480的深度图像。

解决方案

p>也许我错了,但我几乎可以肯定,问题是你的顺序。



我认为你应该改变它 before depth.start()之后 depth.create(device,SENSOR_DEPTH)



所以它应该是这样的

$ b $

如果我记得正确, b

  ... 

if(device.getSensorInfo(SENSOR_DEPTH)!= NULL)
{
rc = depth.create(device,SENSOR_DEPTH);
if(rc!= STATUS_OK)
{
cout< 无法创建深度流< endl<< OpenNI :: getExtendedError()<< endl;
return 3;
}
}

//设置分辨率
//深度模式
cout< 深度模式< endl;
const openni :: SensorInfo * sinfo = device.getSensorInfo(openni :: SENSOR_DEPTH);
const openni :: Array< openni :: VideoMode>& modesDepth = sinfo-> getSupportedVideoModes();
rc = depth.setVideoMode(modesDepth [0]);
if(openni :: STATUS_OK!= rc)
{
cout< error:depth fromat not supprted ...< endl;
}

rc = depth.start();
if(rc!= STATUS_OK)
{
cout< 无法启动深度流< endl<< OpenNI :: getExtendedError()<< endl;
return 4;
}

VideoFrameRef框架;



...



这有助于你,如果没有,请添加评论。我有一个类似的代码在git存储库中工作我告诉你,有一天,用一个PrimeSense的胭脂红相机测试。


I want to read depth frame at 640x480.
I am using windows 8.1 64bit, openni2 32bit, kinect:PSMP05000,PSCM04900(PrimeSense)

I take code reference from here:
cannot set VGA resolution
Simple Read

Combined to this code:
main.cpp
OniSampleUtilities.h
SimpleRead.vcxproj
should be compiled if you install openni2 32bit from here:
OpeniNI 2

#include "iostream"
#include "OpenNI.h"
#include "OniSampleUtilities.h" 

#define SAMPLE_READ_WAIT_TIMEOUT 2000 //2000ms

using namespace openni;
using namespace std;

int main()
{
    Status rc = OpenNI::initialize();
    if (rc != STATUS_OK)
    {
        cout << "Initialize failed:" << endl << OpenNI::getExtendedError() << endl;
        return 1;
    }

    Device device;
    rc = device.open(ANY_DEVICE);
    if (rc != STATUS_OK)
    {
        cout << "Couldn't open device" << endl << OpenNI::getExtendedError() << endl;
        return 2;
    }

    VideoStream depth;

    if (device.getSensorInfo(SENSOR_DEPTH) != NULL)
    {
        rc = depth.create(device, SENSOR_DEPTH);
        if (rc != STATUS_OK)
        {
            cout << "Couldn't create depth stream" << endl << OpenNI::getExtendedError() << endl;
            return 3;
        }
    }

    rc = depth.start();
    if (rc != STATUS_OK)
    {
        cout << "Couldn't start the depth stream" << endl << OpenNI::getExtendedError() << endl;
        return 4;
    }

    VideoFrameRef frame;

    // set resolution
    // depth modes
    cout << "Depth modes" << endl;
    const openni::SensorInfo* sinfo = device.getSensorInfo(openni::SENSOR_DEPTH); // select index=4 640x480, 30 fps, 1mm
    const openni::Array< openni::VideoMode>& modesDepth = sinfo->getSupportedVideoModes();
    for (int i = 0; i<modesDepth.getSize(); i++) {
        printf("%i: %ix%i, %i fps, %i format\n", i, modesDepth[i].getResolutionX(), modesDepth[i].getResolutionY(),
            modesDepth[i].getFps(), modesDepth[i].getPixelFormat()); //PIXEL_FORMAT_DEPTH_1_MM = 100, PIXEL_FORMAT_DEPTH_100_UM
    }
    rc = depth.setVideoMode(modesDepth[0]);
    if (openni::STATUS_OK != rc)
    {
        cout << "error: depth fromat not supprted..." << endl;
    }
    system("pause");
    while (!wasKeyboardHit())
    {
        int changedStreamDummy;
        VideoStream* pStream = &depth;
        rc = OpenNI::waitForAnyStream(&pStream, 1, &changedStreamDummy, SAMPLE_READ_WAIT_TIMEOUT);
        if (rc != STATUS_OK)
        {
            cout << "Wait failed! (timeout is " << SAMPLE_READ_WAIT_TIMEOUT << " ms)" << endl << OpenNI::getExtendedError() << endl;
            continue;
        }

        rc = depth.readFrame(&frame);
        if (rc != STATUS_OK)
        {
            cout << "Read failed!" << endl << OpenNI::getExtendedError() << endl;
            continue;
        }

        if (frame.getVideoMode().getPixelFormat() != PIXEL_FORMAT_DEPTH_1_MM && frame.getVideoMode().getPixelFormat() != PIXEL_FORMAT_DEPTH_100_UM)
        {
            cout << "Unexpected frame format" << endl;
            continue;
        }

        DepthPixel* pDepth = (DepthPixel*)frame.getData();

        int middleIndex = (frame.getHeight()+1)*frame.getWidth()/2;

        printf("[%08llu] %8d\n", (long long)frame.getTimestamp(), pDepth[middleIndex]);
    }

    depth.stop();
    depth.destroy();
    device.close();
    OpenNI::shutdown();

    return 0;
}

There is 6 mode of operation:

0: 320x240, 30 fps, 100 format
1: 320x240, 30 fps, 101 format
2: 320x240, 60 fps, 100 format
3: 320x240, 60 fps, 101 format
4: 640x480, 30 fps, 100 format
5: 640x480, 30 fps, 101 format

It can read only from modes=0-3.
At mode 4,5 i get timeout.
How i can read depth frame at 640x480?

Thanks for the help,
Tal.

====================================================
new information:

I use also this line, and i get the same results:

const openni::SensorInfo* sinfo = &(depth.getSensorInfo());


This line never execute at any mode:

cout << "error: depth fromat not supprted..." << endl;


At mode 4,5 I always get this line execute:

cout << "Wait failed! (timeout is " << SAMPLE_READ_WAIT_TIMEOUT << " ms)" << endl << OpenNI::getExtendedError() << endl;


I think maybe it a bug at openni2.
At openni1, I can read depth image at 640x480, in the same computer,os and device.

解决方案

Maybe I am wrong, but I am almost sure that the problem is the order that you are doing it.

I think you should change it before depth.start() and after depth.create(device, SENSOR_DEPTH)

If I remember correctly, once it has started you may bot change the resolution of the stream.

So it should be something like this

...

if (device.getSensorInfo(SENSOR_DEPTH) != NULL)
{
    rc = depth.create(device, SENSOR_DEPTH);
    if (rc != STATUS_OK)
    {
        cout << "Couldn't create depth stream" << endl << OpenNI::getExtendedError() << endl;
        return 3;
    }
}

// set resolution
// depth modes
cout << "Depth modes" << endl;
const openni::SensorInfo* sinfo = device.getSensorInfo(openni::SENSOR_DEPTH);
const openni::Array< openni::VideoMode>& modesDepth = sinfo->getSupportedVideoModes();
rc = depth.setVideoMode(modesDepth[0]);
if (openni::STATUS_OK != rc)
{
    cout << "error: depth fromat not supprted..." << endl;
}

rc = depth.start();
if (rc != STATUS_OK)
{
    cout << "Couldn't start the depth stream" << endl << OpenNI::getExtendedError() << endl;
    return 4;
}

VideoFrameRef frame;



...

I hope that this helps you, if not, please add a comment. I have a similar code working in the git repository I show you the other day, tested with a PrimeSense carmine camera.

这篇关于更改openni2上的解决方案不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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