RealSense SR300 坑4米 获取相机参数

news/2025/2/15 19:04:57/

硬件

相机的原理我了解的也不甚多,看到一篇讲的很好的文章,就在这里引用了~

SR300设备的红外线发射器(IR Laser Projector)发射的“结构光”,经物体反射后会被红外线传感器(IR Camera Lens)接收。由于红外线到反射物体表面的距离不同,红外传感器捕到的“结构光”图案的位置和形状会发生变化,根据这些由实感图像处理芯片就能计算出物体表面的空间信息,再用三角测距原理进行“深度”计算,进而重现3D场景。
————————————————
版权声明:本文为CSDN博主「codekiller_」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/codekiller_/article/details/63685891

获取参数c代码

秉持着对c语言深深的热爱,我还是用c写了获取内参等硬件参数的代码。

#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
#include<iostream>
#include<opencv2/opencv.hpp>float get_depth_scale(rs2::device dev) 
{    // Go over the device's sensors    for (rs2::sensor& sensor : dev.query_sensors())    {       // Check if the sensor if a depth sensor        if (rs2::depth_sensor dpt = sensor.as<rs2::depth_sensor>())  {            return dpt.get_depth_scale();        }    }    throw std::runtime_error("Device does not have a depth sensor");
} 
int main(int argc, char * argv[]) try
{rs2::log_to_console(RS2_LOG_SEVERITY_ERROR);rs2::context ctx;auto devs = ctx.query_devices();                  ///获取设备列表int device_num = devs.size();std::cout << "device num: " << device_num << std::endl;///设备数量rs2::device dev = devs[0];char serial_number[100] = { 0 };strcpy(serial_number, dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER));printf("serial_number: %s\n", serial_number);rs2::config cfg;cfg.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_BGR8, 30);///配置深度图像流:分辨率640*480,图像格式:Z16, 帧率:30帧/秒cfg.enable_stream(RS2_STREAM_DEPTH, 640, 480, RS2_FORMAT_Z16, 30);///生成Realsense管道,用来封装实际的相机设备rs2::pipeline pipe;pipe.start(cfg); ///根据给定的配置启动相机管道//获取深度比例系数rs2::pipeline_profile profile = pipe.start(cfg);;float depth_scale = get_depth_scale(profile.get_device());printf("deep_scale:%f\n", depth_scale);system("pause");rs2::frameset data;data = pipe.wait_for_frames();///等待一帧数据,默认等待5srs2::depth_frame depth = data.get_depth_frame(); ///获取深度图像数据rs2::video_frame color = data.get_color_frame();  ///获取彩色图像数据rs2::stream_profile dprofile = depth.get_profile();rs2::stream_profile cprofile = color.get_profile();///获取彩色相机内参rs2::video_stream_profile cvsprofile(cprofile);rs2_intrinsics color_intrin = cvsprofile.get_intrinsics();std::cout << "\ncolor intrinsics: ";std::cout << color_intrin.width << "  " << color_intrin.height << "  ";std::cout << color_intrin.ppx << "  " << color_intrin.ppy << "  ";std::cout << color_intrin.fx << "  " << color_intrin.fy << std::endl;std::cout << "coeffs: ";for (auto value : color_intrin.coeffs)std::cout << value << "  ";std::cout << std::endl;std::cout << "distortion model: " << color_intrin.model << std::endl;///畸变模型///获取深度相机内参rs2::video_stream_profile dvsprofile(dprofile);rs2_intrinsics depth_intrin = dvsprofile.get_intrinsics();std::cout << "\ndepth intrinsics: ";std::cout << depth_intrin.width << "  " << depth_intrin.height << "  ";std::cout << depth_intrin.ppx << "  " << depth_intrin.ppy << "  ";std::cout << depth_intrin.fx << "  " << depth_intrin.fy << std::endl;std::cout << "coeffs: ";for (auto value : depth_intrin.coeffs)std::cout << value << "  ";std::cout << std::endl;std::cout << "distortion model: " << depth_intrin.model << std::endl;///畸变模型///获取深度相机相对于彩色相机的外参,即变换矩阵: P_color = R * P_depth + Trs2_extrinsics extrin = dprofile.get_extrinsics_to(cprofile);std::cout << "\nextrinsics of depth camera to color camera: \nrotaion: " << std::endl;for (int i = 0; i < 3; ++i){for (int j = 0; j < 3; ++j) {float value = extrin.rotation[3 * i + j];std::cout << value << "  ";}std::cout << std::endl;}std::cout << std::endl;std::cout << "translation: ";for (auto value : extrin.translation)std::cout << value << "  ";std::cout << std::endl;while (1){///等待一帧数据,默认等待5sdata = pipe.wait_for_frames();rs2::depth_frame depth = data.get_depth_frame(); ///获取深度图像数据rs2::video_frame color = data.get_color_frame();  ///获取彩色图像数据int color_width = color.get_width();int color_height = color.get_height();int depth_width = depth.get_width();int depth_height = depth.get_height();if (!color || !depth) break;                ///如果获取不到数据则退出///将彩色图像和深度图像转换为Opencv格式cv::Mat image(cv::Size(color_width, color_height), CV_8UC3, (void*)color.get_data(), cv::Mat::AUTO_STEP);cv::Mat depthmat(cv::Size(depth_width, depth_height), CV_16U, (void*)depth.get_data(), cv::Mat::AUTO_STEP);///显示cv::imshow("image", image);cv::imshow("depth", depthmat);cv::waitKey(1);}system("pause");return EXIT_SUCCESS;
}
catch (const rs2::error & e)
{///捕获相机设备的异常std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n    " << e.what() << std::endl;system("pause");return EXIT_FAILURE;
}
catch (const std::exception& e)
{std::cerr << "Other error : " << e.what() << std::endl;system("pause");return EXIT_FAILURE;
}

http://www.ppmy.cn/news/832552.html

相关文章

JSON 的定义

C#中一般运用到的文本信息有三种&#xff1a;1.xml 2.JSON 3.EXCEL 所以今天梳理一下json... JSON JSON 是存储和交换文本信息的语法。类似 XML。 JSON 比 XML 更小、更快&#xff0c;更易解析。JSON跟XML一样是一种是数据格式。JSON(JavaScript Object Notation) 是一种轻量级…

【新版系统架构】第十七章-通信系统架构设计理论与实践

软考-系统架构设计师知识点提炼-系统架构设计师教程&#xff08;第2版&#xff09; 第一章-绪论第二章-计算机系统基础知识&#xff08;一&#xff09;第二章-计算机系统基础知识&#xff08;二&#xff09;第三章-信息系统基础知识第四章-信息安全技术基础知识第五章-软件工程…

QT中widget隐藏了子对象,不关闭widget,无法刷新最小高度解决办法

QT中widget隐藏了子对象&#xff0c;不关闭widget&#xff0c;无法刷新最小高度 今天在QT开发中&#xff0c;遇到了一个头疼的问题&#xff0c;在不关闭QWidget对象的前提条件下&#xff0c;更改了widget部分子对象的可见性&#xff0c;然后调用下面的接口函数&#xff1a; re…

DellR730修改远程管理卡iDRAC用户名和密码

Dell R730的远程管理卡设置1.重启服务器,首选项F2 System Setup;2.进入F2之后选择第二项 iDRAC Settings;3.选择下面的User Configuration4.现在进入的界面即为远程管理卡的用户名和密码设置界面默认用户名root密码自己设置 简单点好 无所谓 转载于:https://blog.51cto.com/wen…

win7 家庭组连接 使用用户账号和密码连接到其他计算机,win7密码正确不能加入家庭组...

win7密码正确组原因及解决方法&#xff1a;单”&#xff0c;然后按照向导中的步骤操作。如运行 Fix It 向导无法解决问题&#xff0c;请参考下面的列表&#xff1a;网络中没有可用的家庭组。若要创建一个家庭组&#xff0c;请参阅创建家庭组。可能未连接到家庭组所在的网络。若…

家庭组使用密码加入后无法访问

家庭组诊断结果为win7文件和打印资源处于联机状态,但未对连接尝试做出 检测到响应。 原因是445端口被封禁。 445端口可以通过两种方法封禁&#xff0c;一种是通过组策略&#xff0c;一种是通过Windows防火墙里的高级选项里的入站规则。 我的是通过组策略被封禁的&#xff0c…

本计算机家庭组的用户名,win7系统电脑,如何设置共享,共享计算机的用户名和密码怎样设置...

百度文库的东西自己能找到方法的。。。XP与WIN7如何共享 第一&#xff0c;双击桌面上网络图标。 第二&#xff0c;单击上面网络共享中心。 第三&#xff0c;单击左边的更改高级共享设置&#xff0c;在这儿设置你的共享方式。 第四&#xff0c;将启用网络发现&#xff0c;启用打…

主板IPMI登录密码帐号

超微主板 用户名&#xff1a;ADMIN 密码&#xff1a;ADMIN&#xff08;2019之前&#xff09; 新批号的IPMI密码均位于CPU盖板或者主板SN信息旁边&#xff0c;会标注IPMI MAC地址和IPMI密码 华硕主板 用户名&#xff1a;admin 密码&#xff1a;admin 泰安主板 用户名&#xff…