IntelRealSense d415深度相机拍照制作数据集python脚本
最近想做一个阴影数据集,手上d415相机像素好一点,就用来调用拍照啦。
上源码:
import pyrealsense2 as rs
import numpy as np
import cv2
# Configure depth and color streams
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 1280, 720, rs.format.bgr8, 30)
# Start streaming
pipeline.start(config)
# 每种样本50个图像,一共八种,50*8=400个初始图像,之后再做数据增广
filePath = "/home/qyt/DataSet/Shadow/"
id = "1"
i = 0
j=0
#只是采集图像,不用深度信息
while i<=50:
frames = pipeline.wait_for_frames()
color_frame = frames.get_color_frame()
# Convert images to numpy arrays 把图像转换为numpy data
color_image = np.asanyarray(color_frame.get_data())
cv2.namedWindow('MyD415')
cv2.imshow('MyD415', color_image)
key = cv2.waitKey(0)
if i < 10:
imageName = "shadow" + id + "_0" + str(i) + ".jpg"
else:
imageName = "shadow" + id + "_" + str(i) + ".jpg"
imagePath = filePath + imageName
if key & 0xFF == ord('q') or key == 27:
cv2.destroyAllWindows()
pipeline.stop()
break
elif key == ord('s'): # 按下s键时保存并退出
cv2.imwrite(imagePath, color_image)
i += 1
#cv2.destroyAllWindows()
j=j+1
#方便看保存到第几张图了
print("iter:",j,"i:", i)