概述
realsense使用ubuntu python读取深度图、彩色图和IMU数据
import pyrealsense2 as rs
import numpy as np
import cv2
import glob
import math
from tqdm import tqdm
import time
from collections import
namedtuple
import os
GyroBias = namedtuple('GyroBias', ['x', 'y', 'z'])
bias = GyroBias(0,0,0)
pipline = 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)
config.enable_stream(rs.stream.gyro, rs.format.motion_xyz32f)
config.enable_stream(rs.stream.accel, rs.format.motion_xyz32f)
pipline.start(config)
align = rs.align(rs.stream.color)
save_dir = '/home/xmj/'+str(time.time())
os.mkdir(save_dir)
last_ts, dt = {}, {}
roll, pitch, yaw = 0, 0, 0
first_accel = True
for i in tqdm(range(300)):
# real time read
frames = pipline.wait_for_frames()
for f in frames:
p = f.get_profile()
fnum = f.get_frame_number()
ts = f.get_timestamp()
t = str(p.stream_type())
if t in last_ts:
dt[t] = (ts - last_ts[t])/1000.
else:
dt[t] = 1/30
last_ts[t] = ts
gyro = frames.first(rs.stream.gyro).as_motion_frame().get_motion_data()
gyro_arr = [gyro.x, gyro.y, gyro.z]
accel = frames.first(rs.stream.accel).as_motion_frame().get_motion_data()
accel_arr = [accel.x, accel.y, accel.z]
# align
aligned_frames = align.process(frames)
# get split_frame
aligned_depth_frame = aligned_frames.get_depth_frame()
color_frame = aligned_frames.get_color_frame()
# realtime save use rs to save ply file
pc = rs.pointcloud()
pc.map_to(color_frame)
points = pc.calculate(aligned_depth_frame)
parray = np.asanyarray(points.get_vertices())
print('points', points, parray.shape)
points.export_to_ply(f'{save_dir}/{i}_rs.ply', color_frame)
# save IMU data
open(f'{save_dir}/{i}_rs.txt', 'w').write(f"{gyro_arr[0]},{gyro_arr[1]},{gyro_arr[2]},{accel_arr[0]},{accel_arr[1]},{accel_arr[2]},{dt['stream.gyro']}")
# Convert images to numpy arrays, use open3d to save ply file
depth_image = np.asanyarray(aligned_depth_frame.get_data())
# 480*640
color_image = np.asanyarray(color_frame.get_data())
np.savez(f'{save_dir}/{i}_rs.npz', data=depth_image)
cv2.imwrite(f'{save_dir}/{i}_rs.png', color_image)
最后
以上就是碧蓝服饰为你收集整理的realsense使用ubuntu python读取深度图、彩色图和IMU数据的全部内容,希望文章能够帮你解决realsense使用ubuntu python读取深度图、彩色图和IMU数据所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复