使用自动曝光:
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的时候发现这方面的中文资料着实算不上多,顺带机翻了官方文档中定义的控制参数表格,希望有所帮助:)文档链接我会贴在最后。

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

被折叠的 条评论
为什么被折叠?



