简体   繁体   English

VideoStream :: setVideoMode()函数不起作用

[英]VideoStream::setVideoMode() function doesn't work

I want to change VideoStream setting in my program, but it doesn't work 我想在程序中更改VideoStream设置,但是不起作用

#include <OpenNI.h>

int main()
{
    OpenNI::initialize();
    Device device;
    device.open(ANY_DEVICE);
    VideoStream depthStream;
    depthStream.create(device, SENSOR_DEPTH);
    depthStream.start();

    VideoMode depthMode;
    depthMode.setFps(20);
    depthMode.setResolution(640, 480);
    depthMode.setPixelFormat(PIXEL_FORMAT_DEPTH_100_UM);
    depthStream.setVideoMode(depthMode);

    ...
}

Even I change depthStream.start() line after setVideoMode() function, but still doesn't work. 即使我在setVideoMode()函数之后更改depthStream.start()行,也仍然无法正常工作。

I changed Fps to 24, 20, 5, 1 but it doesn't change anything. 我将Fps更改为24、20、5、1,但没有任何改变。

ps : This is my simple code, without error handling. ps:这是我的简单代码,没有错误处理。


Edit: 编辑:

Answer: with the help of dear "api55" i found that my device (Kinect Xbox) support only one mode of videoMode. 答:在亲爱的“ api55”的帮助下,我发现我的设备(Kinect Xbox)仅支持videoMode的一种模式。 so I can't change it. 所以我不能改变

My only supported video is : 我唯一支持的视频是:

FPS:30
Width:640
Height:480

I change the VideoMode succesfully in a code a did before. 我在以前的代码中成功更改了VideoMode。 After creating the VideoStream you should do something like: 创建VideoStream之后,您应该执行以下操作:

rc = depth.create(device, openni::SENSOR_DEPTH);
if (rc != openni::STATUS_OK)
    error_manager(3);

// set the new resolution and fps
openni::VideoMode depth_videoMode  = depth.getVideoMode();
depth_videoMode.setResolution(frame_width,frame_height);
depth_videoMode.setFps(30);
depth.setVideoMode(depth_videoMode);

rc = depth.start();
if (rc != openni::STATUS_OK)
    error_manager(4);

First I get the VideoMode that is inside the stream to conserve the other values and only change what I wanted. 首先,我获得了流内部的VideoMode以保留其他值,并仅更改我想要的内容。 I think your code should work, but not all settings work in all cameras. 我认为您的代码应该可以使用,但并非所有设置都适用于所有相机。 To check the possible settings you can use the function openni::VideoStream::getSensorInfo . 要检查可能的设置,可以使用功能openni::VideoStream::getSensorInfo The code to check this should be something like: 检查此代码应类似于:

#include <OpenNI.h>

int main()
{
    OpenNI::initialize();
    Device device;
    device.open(ANY_DEVICE);
    VideoStream depthStream;
    depthStream.create(device, SENSOR_DEPTH);
    depthStream.start();

    SensorInfo& info = depthStream.getSensorInfo();
    Array& videoModes = info.getSupportedVideoModes();
    for (int i = 0; i < videoModes.getSize(); i++){
         std::cout << "VideoMode " << i << std::endl;
         std::cout << "FPS:" << videoModes[i].getFps() << std::endl;
         std::cout << "Width:" << videoModes[i].getResolutionX() << std::endl;
         std::cout << "Height:" << videoModes[i].getResolutionY() << std::endl;
    }

    ...
}

I haven't test this last piece of code, so it may have errors, but you get the idea of it. 我没有测试这最后一段代码,因此可能会有错误,但是您明白了。 The supported settings change with each camera, but I think the supported FPS in my camera were 15 and 30. 每个相机支持的设置都会改变,但是我认为相机支持的FPS是15和30。

I hope this helps you 我希望这可以帮助你

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

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