intel realsense 读取深度信息

目前所用使用的代码均为python,代码编辑器使用Pycharm 社区版,操作系统为Ubuntu2204的Linux系统。Pycharm直接下载安装即可。

为了方便环境管理及不同运行环境之间的自由切换,本项目安装了Conda管理工具Miniconda[1](备注:Anaconda更加完善,但容量更大,两者皆可)。

Reference:

[1] Miniconda — conda documentation

安装好conda之后创建一个conda虚拟环境,例如python10_realsense2

# create a python environment named python_realsense2 with python 3.10
conda create --name==python_realsense2 python==3.10
# activate the environment
conda activate python_realsense2

图片采集部分,使用Intel RealSense D435i深度相机。该相机有集成的开发工具包,只需要安装即可使用。目前只安装了python工具包pyrealsense2。

# install the librealsense python wrapper using pip
pip install pyrealsense2

Reference:

https://github.com/IntelRealSense/librealsenseicon-default.png?t=N7T8https://github.com/IntelRealSense/librealsense通过相机读取数据,主要包括图片和深度值,通过保存为RGB图片和深度矩阵的形式:

import pyrealsense2 as rs
import numpy as np
import cv2


pipeline = rs.pipeline()
config = rs.config()

config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)

align_to = rs.stream.color
align = rs.align(align_to)

cfg = pipeline.start(config)
t = 0
try:

    while True:
        frames = pipeline.wait_for_frames()
        frames_aligned = align.process(frames)
        depth_frame = frames_aligned.get_depth_frame()
        color_frame = frames_aligned.get_color_frame()

        depth_np = np.asanyarray(depth_frame.get_data())
        color_np = np.asanyarray(color_frame.get_data())

        cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)
        cv2.imshow('RealSense', color_np)
        key = cv2.waitKey(1)
        if key in (27, ord("q")):
            break
        if key == ord("s"):
            cv2.imwrite("color_%d.png" % t, color_np)
            np.save("depth_%d" % t, depth_np)
            t += 1

finally:
    pipeline.stop()
    print("OVER")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
您可以使用Intel RealSense相机来读取深度、彩色和红外数据。以下是一些基本的步骤: 1. 安装RealSense SDK:从Intel官方网站下载并安装RealSense SDK软件包。 2. 连接相机:将RealSense相机通过USB接口连接到计算机。 3. 初始化相机:在代码中初始化RealSense相机,打开设备并设置所需的参数。 4. 读取数据:使用相机对象读取数据帧。您可以选择读取深度图像、颜色图像或红外图像。 下面是一个使用Python和pyrealsense库的简单示例: ```python import pyrealsense2 as rs # 初始化RealSense相机 pipeline = rs.pipeline() config = rs.config() config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) config.enable_stream(rs.stream.color, 640, 480, rs.format.rgb8, 30) pipeline.start(config) try: while True: # 等待新的数据帧 frames = pipeline.wait_for_frames() # 获取深度图像和颜色图像 depth_frame = frames.get_depth_frame() color_frame = frames.get_color_frame() if not depth_frame or not color_frame: continue # 处理深度图像和颜色图像 depth_image = np.asanyarray(depth_frame.get_data()) color_image = np.asanyarray(color_frame.get_data()) # 显示图像或进行其他操作 finally: # 停止相机并关闭窗口 pipeline.stop() ``` 这只是一个基本的示例,您可以根据您的需求进行进一步的处理和操作。请注意,此示例使用了pyrealsense库,您可能需要先安装该库。您也可以使用其他RealSense SDK支持的编程语言进行相似的操作。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值