realsence 455 查看左右摄像头

前言

我打算使用realsence的左右连个摄像头去自己标定配准、然后计算距离的,就需要找s、下载包。

没成想,这个455的左右摄像头是红外的

步骤

  • 安装sdk:

Intel RealSense SDK 2.0 – Intel RealSense Depth and Tracking cameras

尽量在win上安装,ubuntu步骤真的要吐

  • 安装python包或者其他包

pip install pyrealsense2

  • 启动代码

代码

RGB

如果设备是旧版本,支持左右rgb的话

import pyrealsense2 as rs
import cv2
import numpy as np

# 创建一个 Realsense 管道
pipeline = rs.pipeline()

# 配置管道以启用左右两个摄像头
config = rs.config()
#config.enable_device_from_file("path/to/bag/file.bag")  # 如果从录制文件中读取,请提供文件路径
config.enable_stream(rs.stream.left)
config.enable_stream(rs.stream.right)

# 启动管道
pipeline.start(config)

try:
    while True:
        # 等待获取一帧数据
        frames = pipeline.wait_for_frames()

        # 获取左右两个摄像头的帧数据
        left_frame = frames.get_color_frame()
        right_frame = frames.get_color_frame()

        # 在这里可以对左右两个帧数据进行处理

        # 显示左右两个摄像头的图像
        left_image = np.asanyarray(left_frame.get_data())
        right_image = np.asanyarray(right_frame.get_data())

        cv2.imshow('Left Camera', left_image)
        cv2.imshow('Right Camera', right_image)

        # 按下 q 键退出循环
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

finally:
    # 关闭管道并且清理资源
    pipeline.stop()
    cv2.destroyAllWindows()

infrared

如果不支持rgb,只能红外了

import pyrealsense2 as rs
import numpy as np
import cv2

# 创建一个 Realsense 管道
pipeline = rs.pipeline()

# 配置管道以启用左右两个摄像头(红外流)
config = rs.config()
config.enable_device_from_file("path/to/bag/file.bag")  # 如果从录制文件中读取,请提供文件路径
config.enable_stream(rs.stream.infrared, 1)  # 左侧红外流
config.enable_stream(rs.stream.infrared, 2)  # 右侧红外流

# 启动管道
pipeline.start(config)

try:
    while True:
        # 等待获取一帧数据
        frames = pipeline.wait_for_frames()

        # 获取左右两个红外流的帧数据
        left_frame = frames.get_infrared_frame(1)
        right_frame = frames.get_infrared_frame(2)

        # 在这里可以对左右两个帧数据进行处理

        # 将红外流的帧数据转换为图像
        left_image = np.asanyarray(left_frame.get_data())
        right_image = np.asanyarray(right_frame.get_data())

        # 显示左右两个红外流的图像
        cv2.imshow('Left Infrared', left_image)
        cv2.imshow('Right Infrared', right_image)

        # 按下 q 键退出循环
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

finally:
    # 关闭管道并且清理资源
    pipeline.stop()
    cv2.destroyAllWindows()

你可能感兴趣的:(技术文档,opencv,计算机视觉,人工智能)