用python写一段程序,让Intel realsenseD435相机同时拍摄三种图像
时间: 2024-02-03 16:11:49 浏览: 28
这里提供一个基本的Python程序,使用Intel RealSense D435相机同时捕获彩色、深度和IR图像。需要使用`pyrealsense2`库来访问相机并获取图像。
```python
import pyrealsense2 as rs
import numpy as np
import cv2
# Configure RealSense pipeline
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30) # Enable color stream
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) # Enable depth stream
config.enable_stream(rs.stream.infrared, 1, 640, 480, rs.format.y8, 30) # Enable IR stream
# Start streaming
pipeline.start(config)
try:
while True:
# Wait for a coherent pair of frames: color and depth
frames = pipeline.wait_for_frames()
color_frame = frames.get_color_frame()
depth_frame = frames.get_depth_frame()
ir_frame = frames.get_infrared_frame(1)
# Convert images to numpy arrays
color_image = np.asanyarray(color_frame.get_data())
depth_image = np.asanyarray(depth_frame.get_data())
ir_image = np.asanyarray(ir_frame.get_data())
# Show images
cv2.imshow('Color', color_image)
cv2.imshow('Depth', depth_image)
cv2.imshow('IR', ir_image)
# Press 'q' to quit
if cv2.waitKey(1) & 0xFF == ord('q'):
break
finally:
# Stop streaming
pipeline.stop()
# Close all windows
cv2.destroyAllWindows()
```
该程序将显示三个窗口,分别显示彩色、深度和IR图像。你可以根据需要修改分辨率、帧速率和其他设置。