【无标题】

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

        # 在彩色图像上绘制一些特征点(示例)
        # 这里选择左上角、中心和右下角三个点作为特征点
        feature_points = [(50, 50), (320, 240), (590, 430)]
        for point in feature_points:
            cv2.circle(color_image, point, 5, (0, 255, 0), -1)

        # 在深度图像上找到对应的特征点并绘制
        for point in feature_points:
            # 获取特征点在彩色图像中的深度值
            depth = depth_frame.get_distance(point[0], point[1])

            # 将特征点的深度值投影到深度图像上
            depth_point = rs.rs2_deproject_pixel_to_point(
                depth_frame.profile.as_video_stream_profile().intrinsics, [point[0], point[1]], depth)

            # 将深度图像坐标转换为整数
            depth_point = np.round(depth_point).astype(int)

            # 绘制特征点在深度图像中的位置
            cv2.circle(color_image, (depth_point[0], depth_point[1]), 5, (255, 0, 0), -1)

        # 显示图像
        cv2.imshow('Color Image with Feature Points', color_image)
import numpy as np
import cv2
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.bgr8, 30)
pipeline.start(config)

# 对齐对象
align_to_color = rs.align(rs.stream.color)

try:
    while True:
        # 等待一对深度和彩色帧
        frames = pipeline.wait_for_frames()
        aligned_frames = align_to_color.process(frames)

        # 获取对齐后的深度和彩色帧
        depth_frame = aligned_frames.get_depth_frame()
        color_frame = aligned_frames.get_color_frame()

        if not depth_frame or not color_frame:
            continue

        # 将彩色图像转换为OpenCV格式
        color_image = np.asanyarray(color_frame.get_data())

        # 在彩色图像上绘制一些特征点(示例)
        # 这里选择左上角、中心和右下角三个点作为特征点
        feature_points = [(50, 50), (320, 240), (590, 430)]
        for point in feature_points:
            cv2.circle(color_image, point, 5, (0, 255, 0), -1)

        # 在深度图像上找到对应的特征点并绘制
        for point in feature_points:
            # 获取特征点在彩色图像中的深度值
            depth = depth_frame.get_distance(point[0], point[1])

            # 将特征点的深度值投影到深度图像上
            depth_point = rs.rs2_deproject_pixel_to_point(
                depth_frame.profile.as_video_stream_profile().intrinsics, [point[0], point[1]], depth)

            # 将深度图像坐标转换为整数
            depth_point = np.round(depth_point).astype(int)

            # 绘制特征点在深度图像中的位置
            cv2.circle(color_image, (depth_point[0], depth_point[1]), 5, (255, 0, 0), -1)

        # 显示图像
        cv2.imshow('Color Image with Feature Points', color_image)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

finally:
    # 关闭OpenCV窗口
    cv2.destroyAllWindows()
    # 停止管道并关闭设备
    pipeline.stop()

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值