z6娱乐

z6娱乐

C++ 彩色流示例代码-Color Stream Viewer

# 彩色示例-ColorViewer

 

职能描述:本示例重要演示了使用SDK获取彩色数据并绘造显示、获取分辨率并选择进行设置、显示彩色图像,,,,,,,,并通过ESC_KEY键退出法式

> 本示例基于C++ High Level API进行演示

 

首先必要创建一个Pipeline,,,,,,,,通过Pipeline能够很容易的打开和关关多种类型的流并获取一组帧数据

ob::Pipeline pipe;

 

获取彩色相机的所有流配置,,,,,,,,蕴含流的分辨率,,,,,,,,帧率,,,,,,,,以及帧的体式

// Create a pipeline with default device
ob::Pipeline pipe;

// Configure which streams to enable or disable for the Pipeline by creating a Config
std::shared_ptr<ob::Config> config = std::make_shared<ob::Config>();

std::shared_ptr<ob::VideoStreamProfile> colorProfile = nullptr;
try {
    // Get all stream profiles of the color camera, including stream resolution, frame rate, and frame format
    auto profiles = pipe.getStreamProfileList(OB_SENSOR_COLOR);
    try {
        // Find the corresponding Profile according to the specified format, and choose the RGB888 format first
        colorProfile = profiles->getVideoStreamProfile(640, 480, OB_FORMAT_YUYV, 30);
    }
    catch(ob::Error &e) {
        // If the specified format is not found, select the first one (default stream profile)
        colorProfile = std::const_pointer_cast<ob::StreamProfile>(profiles->getProfile(OB_PROFILE_DEFAULT))->as<ob::VideoStreamProfile>();
    }
    config->enableStream(colorProfile);
}
catch(ob::Error &e) {
    std::cerr << "Current device is not support color sensor!" << std::endl;
    exit(EXIT_FAILURE);
}

```

启动在Config中配置的流

pipe.start(config);

 

以阻塞的方式期待一帧数据,,,,,,,,该帧是一个复合。。。。。,,,,,,里面蕴含配置里启用的所有流的帧数据,,,,,,,,并设置帧的期待超不断间

auto frameSet = pipe.waitForFrames(100);    //设置期待功夫为100ms

 

每30帧打印一次metadata

// print metadata every 30 frames
auto index = colorFrame->index();
if(index % 30 == 0) {
    std::cout << "*************************** Color Frame #" << index << " Metadata List ********************************" << std::endl;
    for(int metaDataType = 0; metaDataType < OB_FRAME_METADATA_TYPE_COUNT; metaDataType++) {
        // Check if it is supported metaDataType for current frame
        if(colorFrame->hasMetadata((OBFrameMetadataType)metaDataType)) {
            // Get the value of the metadata
            std::cout << metaDataTypes[metaDataType] << ": " << colorFrame->getMetadataValue((OBFrameMetadataType)metaDataType) << std::endl;
        }
        else {
            std::cout << metaDataTypes[metaDataType] << ": " << "unsupported" << std::endl;
        }
    }
    std::cout << "********************************************************************************" << std::endl << std::endl;
}

 

终场Pipeline,,,,,,,,将不再产生帧数据

pipe.stop();

最终的彩色图显示如下

image.png

法式正常退出之后资源将会自动开释


【网站地图】【sitemap】