Skip to content

Instantly share code, notes, and snippets.

@ochilab
Last active July 1, 2020 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochilab/955de42f45d58f4cfdcb3d31a6128f9b to your computer and use it in GitHub Desktop.
Save ochilab/955de42f45d58f4cfdcb3d31a6128f9b to your computer and use it in GitHub Desktop.
RealsenseのDepthデータをMulti-Tiffに保存する
# -*- coding: utf-8 -*-
# use tiffile library
# https://pypi.org/project/tifffile/
import pyrealsense2 as rs
import numpy as np
import tifffile
#1280*720
resX=1280
resY=720
# Configure depth and color streams
pipeline = rs.pipeline()
config = rs.config()
config.enable_device_from_file('depth10sec.bag')
config.enable_stream(rs.stream.depth, resX, resY, rs.format.z16, 30)
# Init
profile = pipeline.start(config)
playback = profile.get_device().as_playback()
playback.set_real_time(False) # <--- very important setting to get all frames
depth_sensor = profile.get_device().first_depth_sensor()
depth_scale = depth_sensor.get_depth_scale()
count=0
oldTimeStamp=0
try:
# for first frame
frames = pipeline.wait_for_frames()
depth_frame = frames.get_depth_frame()
currentTimestamp = depth_frame.timestamp
i=0
while (True):
depth_frame = frames.get_depth_frame()
if not depth_frame:
continue
# Get Depth data
depth_image = np.asanyarray(depth_frame.get_data())
#Save multi-Tiff
tifffile.imsave('depth16.tif', depth_image, compress=6, append=True)
print(i)
i +=1
# フレーム待ち(Depth & Color)
frames = pipeline.wait_for_frames()
depth_frame = frames.get_depth_frame()
oldTimeStamp=currentTimestamp
currentTimestamp = depth_frame.timestamp
if oldTimeStamp>=currentTimestamp:
break
finally:
pipeline.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment