簡體   English   中英

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

[英]VideoStream::setVideoMode() function 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);

    ...
}

即使我在setVideoMode()函數之后更改depthStream.start()行,也仍然無法正常工作。

我將Fps更改為24、20、5、1,但沒有任何改變。

ps:這是我的簡單代碼,沒有錯誤處理。


編輯:

答:在親愛的“ api55”的幫助下,我發現我的設備(Kinect Xbox)僅支持videoMode的一種模式。 所以我不能改變

我唯一支持的視頻是:

FPS:30
Width:640
Height:480

我在以前的代碼中成功更改了VideoMode。 創建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);

首先,我獲得了流內部的VideoMode以保留其他值,並僅更改我想要的內容。 我認為您的代碼應該可以使用,但並非所有設置都適用於所有相機。 要檢查可能的設置,可以使用功能openni::VideoStream::getSensorInfo 檢查此代碼應類似於:

#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;
    }

    ...
}

我沒有測試這最后一段代碼,因此可能會有錯誤,但是您明白了。 每個相機支持的設置都會改變,但是我認為相機支持的FPS是15和30。

我希望這可以幫助你

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM