yolov5+D405深度相机测距

前言

yolov5+D405深度相机测距


提示:以下是本篇文章正文内容,下面案例可供参考

一、D405测距python开发例程

代码如下(示例):

import pyrealsense2 as rs

# 创建和启动D405相机
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
profile = pipeline.start(config)

# 获取深度传感器实例
depth_sensor = profile.get_device().first_depth_sensor()

# 调整深度传感器参数(可根据需要调整)
depth_sensor.set_option(rs.option.visual_preset, 2)     
depth_sensor.set_option(rs.option.confidence_threshold, 3)
depth_sensor.set_option(rs.option.min_distance, 0.1)
depth_sensor.set_option(rs.option.max_distance, 10.0)

try:
    # 循环获取深度图像并打印测量值
    while True:
        # 等待深度数据准备就绪
        frames = pipeline.wait_for_frames()
        depth_frame = frames.get_depth_frame()
        if not depth_frame:
            continue
        
        # 获取图像宽度和高度(用于计算距离值)
        width = depth_frame.get_width()
        height = depth_frame.get_height()

        # 计算中心点处的距离值
        x = int(width / 2)
        y = int(height / 2)
        dist_to_center = depth_frame.get_distance(x, y)
        print("Distance to center: ", dist_to_center)
                
finally:
    # 停止相机
    pipeline.stop()

2.将D405相机RGB图格式换成opencv格式放入yolo中检测

pipeline.wait_for_frames()会返回D405深度相机的当前帧数据,其中包括RGB图像、深度图像、红外图像等,因此不能直接将它作为yolov5检测模型的输入。yolov5检测需要的是单张图片或图片列表。

所以,在使用yolov5进行检测之前,您需要从获取到的帧数据中提取RGB图像或深度图像,并把它们作为yolov5模型的输入。通常情况下,我们会把RGB图像作为yolov5检测模型的输入,这些RGB图像可以通过以下代码获取:

frames = pipeline.wait_for_frames()
color_frame = frames.get_color_frame()

img = np.asanyarray(color_frame.get_data())

现在,你已经获取了一张RGB图像img,可以将其用作yolov5模型的输入了。同时注意,如果您要使用深度图像,请使用frames.get_depth_frame()方法获取深度图像数据。

另外,D405深度相机输出的RGB图像和常规的USB相机输出的RGB图像可能有所不同,需要根据实际情况做对应的调整。

img 中的像素点坐标与 frames 中深度图像的像素点坐标一一对应。

具体地说,D405深度相机输出的RGB和深度帧的分辨率相同,默认为 640x480。因此,在从 frames 中获取深度图像时,它的大小与从 img 中获取的 RGB 图像的大小(即大小为 [height, width])相同,每个像素在两个图像中的位置都相同。 因此,在这两个图像之间进行像素级的匹配是很容易的。

也就是说,如果需要通过 RGB 图像中的某个像素点来查找深度图像上海拔点处的距离值,则可以用该像素点的坐标轴值作为索引来提取深度图像中的相应深度值。


总结

如果没有实际的 D405 相机设备,但是希望测试针对该相机的应用程序,可以使用线上仿真器。 Intel® RealSense™ 官方提供了一个在线的 RealSense Depth Camera Simulator,名为"Intel® RealSense™ Depth Camera Simulator",它模拟了相机的输出和工作方式。您可以通过该仿真器轻松测试和调试 D405 相机的代码并验证其可行性。以下是如何使用该仿真器的简要说明:

  1. 访问网站:打开 "Intel® RealSense™ Depth Camera Simulator" 网站,网址为 https://app.intelrealsense.com/depth-camera-simulator.html。
  2. 选择相机型号:在网页上选择要仿真的相机型号,并进行相关设置和配置。
  3. 启动仿真器:启动相应的仿真器,在页面上生成虚拟相机模型。
  4. 进行模拟测试: 在仿真器中运行您针对 D405 相机编写的应用程序,并观察输出结果、FPS(每秒帧率)、深度图、点云等。
  • 2
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
回答: 要安装英特尔D405深度相机,首先需要重新编译系统内核,以使内核能够识别D405i相机。这涉及到在内核编译过程中打补丁,将D405i的USB信息添加到相关文件中。\[1\]接下来,您需要安装ROS的一些包和依赖项。您可以使用以下命令安装rosinstall、python-rosinstall-generator、python-wstool和build-essential等软件包:sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential\[2\]最后,您需要安装ROS的官方包,以便与D405i相机进行通信。根据您使用的ROS版本,您可以使用以下命令安装适当的包://melodic sudo apt install ros-melodic-realsense2-camera sudo apt install ros-melodic-realsense2-description //kinetic sudo apt install ros-kinetic-realsense2-camera sudo apt install ros-kinetic-realsense2-description\[3\]通过按照这些步骤进行操作,您应该能够成功安装英特尔D405深度相机。 #### 引用[.reference_title] - *1* [英伟达 Jetson TX2 开发板安装英特尔 D435i 深度相机驱动](https://blog.csdn.net/SIR_wkp/article/details/103254051)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [RoboMaster视觉 深度相机(1):Ubuntu20.04上安装Intel D435深度相机SDK与ROS](https://blog.csdn.net/Yunhua__/article/details/122134729)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [ROS学习笔记(实践一)--英特尔D435i深度相机调试](https://blog.csdn.net/weixin_41866783/article/details/119342053)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值