AG·尊龙凯时 - 人生就是搏!AG·尊龙凯时

AG·尊龙凯时 - 人生就是搏!AG·尊龙凯时

C++ 深度HDR示例代码-Hdr Merge

# HDR示例-HdrMerge

 

支持设备: Gemini 330系列相机,例如:Gemini G335

 

功能描述:演示使用HDR操作,显示HDR处理后的图像,并通过ESC_KEY键退出程序

 

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

 

创建Pipeline,进行流配置

// 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> irProfile = nullptr;
try {
    // Get all stream profiles of the ir camera, including stream resolution, frame rate, and frame format
    auto irProfiles = pipe.getStreamProfileList(OB_SENSOR_IR_LEFT);
    if(irProfiles) {
        irProfile = std::const_pointer_cast<ob::StreamProfile>(irProfiles->getProfile(OB_PROFILE_DEFAULT))->as<ob::VideoStreamProfile>();
    }
    config->enableStream(irProfile);
}
catch(...) {
    std::cerr << "Current device is not support ir sensor!" << std::endl;
    exit(EXIT_FAILURE);
}

// Get all stream profiles of the depth camera, including stream resolution, frame rate, and frame format
auto                                    depthProfiles = pipe.getStreamProfileList(OB_SENSOR_DEPTH);
std::shared_ptr<ob::VideoStreamProfile> depthProfile  = nullptr;
if(depthProfiles) {
    depthProfile = std::const_pointer_cast<ob::StreamProfile>(depthProfiles->getProfile(OB_PROFILE_DEFAULT))->as<ob::VideoStreamProfile>();
}
config->enableStream(depthProfile);

 

打开HDR处理

// Create HdrMerage post processor
ob::HdrMerge hdrMerge;

// open hdr merage
if(pipe.getDevice()->isPropertySupported(OB_STRUCT_DEPTH_HDR_CONFIG, OB_PERMISSION_READ_WRITE)) {
    // Get depth exposure value range,the exposure_1 and exposure_2 in OBHdrConfig can be adjusted.
    OBIntPropertyRange depthExpRange = pipe.getDevice()->getIntPropertyRange(OB_PROP_DEPTH_EXPOSURE_INT);
    // Get depth gain value range,,the gain_1 and gain_1 in OBHdrConfig can be adjusted.
    OBIntPropertyRange depthGainRange = pipe.getDevice()->getIntPropertyRange(OB_PROP_DEPTH_GAIN_INT);

    OBHdrConfig obHdrConfig;
    uint32_t    dataSize = sizeof(OBHdrConfig);
    pipe.getDevice()->getStructuredData(OB_STRUCT_DEPTH_HDR_CONFIG, &obHdrConfig, &dataSize);
    // open hdr
    obHdrConfig.enable = true;

    pipe.getDevice()->setStructuredData(OB_STRUCT_DEPTH_HDR_CONFIG, &obHdrConfig, sizeof(OBHdrConfig));
}

 

开启pipeline

pipe.start(config);

 

 

获取HDR处理后的图像

auto leftIRFrame = frameSet->getFrame(OB_FRAME_IR_LEFT);
if(leftIRFrame) {
    framesForRender.push_back(leftIRFrame);
}

auto depthFrame = frameSet->depthFrame();
if(depthFrame != nullptr) {
    auto newFrame = hdrMerge.process(frameSet);
    auto newFrameSet = newFrame->as<ob::FrameSet>();
    if(newFrameSet) {
        depthFrame = newFrameSet->depthFrame();
        if(depthFrame) {
            framesForRender.push_back(depthFrame);
        }
    }
}

 

关闭pipeline

pipe.stop();

 

关闭Hdr处理

if(pipe.getDevice()->isPropertySupported(OB_STRUCT_DEPTH_HDR_CONFIG, OB_PERMISSION_READ_WRITE)) {
    OBHdrConfig obHdrConfig;
    uint32_t    dataSize = sizeof(OBHdrConfig);
    pipe.getDevice()->getStructuredData(OB_STRUCT_DEPTH_HDR_CONFIG, &obHdrConfig, &dataSize);
    obHdrConfig.enable = false;
    pipe.getDevice()->setStructuredData(OB_STRUCT_DEPTH_HDR_CONFIG, &obHdrConfig, sizeof(OBHdrConfig));
}

```

预期输出:

image.png 


AG·尊龙凯时