Intel Realsense D系列深度相机 使用C++设置手动/自动调整曝光

本文档介绍了如何使用librealsense库控制Realsense相机的自动和手动曝光,以及如何获取和设置其他关键参数。通过示例代码展示了如何初始化相机并调整曝光参数,同时列举了众多可用的相机控制选项,包括背光补偿、亮度、对比度等,为Realsense用户提供了详细的参考信息。

使用自动曝光:

sen.set_option(RS2_OPTION_AUTO_EXPOSURE_PRIORITY, true);

使用手动曝光:

sen.set_option(RS2_OPTION_EXPOSURE, camera_exposure);
//camera_exposure即为曝光参数

另,若想获取当前相机的曝光参数可以使用:

sen.get_option(RS2_OPTION_EXPOSURE)

附上调用Demo,由于是没有imu的型号所以只拉了俩个视频流然后用opencv显示:

#include <librealsense2/rs.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>

const int camera_frame_width  = 640;
const int camera_frame_height = 480;
const int camera_fps          = 60;

int camera_exposure     = 200;

rs2::pipeline         pipe;

void InitCamera(){
    rs2::context          ctx;
    rs2::config           cfg;
    rs2::sensor           sen;
    rs2::pipeline_profile profile;
    auto list = ctx.query_devices();
    if (list.size() <= 0){
        //exit(0);
        throw std::runtime_error("No device detected. Is it plugged in?");
    }
    rs2::device dev = list.front();

    cfg.enable_stream(RS2_STREAM_COLOR, camera_frame_width, camera_frame_height, RS2_FORMAT_BGR8, camera_fps);//向配置添加所需的流
    cfg.enable_stream(RS2_STREAM_DEPTH, camera_frame_width, camera_frame_height, RS2_FORMAT_Z16,  camera_fps);

    pipe = rs2::pipeline();
    profile = pipe.start(cfg);
    sen = pipe.get_active_profile().get_device().query_sensors()[1];

    if (camera_exposure < 0){
        sen.set_option(RS2_OPTION_AUTO_EXPOSURE_PRIORITY, true);
        std::cout << "自动曝光 参数为[" << sen.get_option(RS2_OPTION_EXPOSURE) << "]" << std::endl;
    }
    else{
        sen.set_option(RS2_OPTION_EXPOSURE, camera_exposure);
        std::cout << "手动曝光 参数为[" << sen.get_option(RS2_OPTION_EXPOSURE) << "]" << std::endl;
    }

    auto depth_stream=profile.get_stream(RS2_STREAM_DEPTH).as<rs2::video_stream_profile>();
    auto color_stream=profile.get_stream(RS2_STREAM_COLOR).as<rs2::video_stream_profile>();
}

int main() {
    InitCamera();
    rs2::frameset frames;
    while (true){
        frames = pipe.wait_for_frames();//等待所有配置的流生成框架

        rs2::align align_to_color(RS2_STREAM_COLOR);
        frames = align_to_color.process(frames);

        rs2::frame color_frame = frames.get_color_frame();
        rs2::frame depth_frame = frames.get_depth_frame();

        cv::Mat frame_color(cv::Size(camera_frame_width, camera_frame_height), CV_8UC3, (void*)color_frame.get_data(), cv::Mat::AUTO_STEP);
        cv::Mat frame_depth(cv::Size(camera_frame_width, camera_frame_height), CV_16U,  (void*)depth_frame.get_data(), cv::Mat::AUTO_STEP);

        cv::imshow("color", frame_color);
        cv::imshow("depth", frame_depth);

        cv::waitKey(1);

    }
    return 0;
}

自己最近写realsense的时候发现这方面的中文资料着实算不上多,顺带机翻了官方文档中定义的控制参数表格,希望有所帮助:)文档链接我会贴在最后。

</
RS2_OPTION_BACKLIGHT_COMPENSATION

启用/禁用彩色背光补偿

RS2_OPTION_BRIGHTNESS

彩色图像亮度

RS2_OPTION_CONTRAST

彩色图像对比度

RS2_OPTION_EXPOSURE

控制彩色相机的曝光时间。 设置任何值将禁用自动曝光

RS2_OPTION_GAIN

彩色图像增益

RS2_OPTION_GAMMA

彩色图像伽玛设置

RS2_OPTION_HUE

彩色图像色调

RS2_OPTION_SATURATION

彩色图像饱和度设置

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值