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()