Last active
December 12, 2019 10:21
-
-
Save zwn/1891390e9adb62b183d3f97c953b2380 to your computer and use it in GitHub Desktop.
Handy realsense t265 examples in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyrealsense2 as rs | |
def main(): | |
pipeline = rs.pipeline() | |
pipeline.start() | |
profile = pipeline.get_active_profile() | |
streams = profile.get_streams() | |
for s in streams: | |
print(f'{s.__class__.__name__}: index:{s.stream_index()} @ {s.fps():>3d}fps type:{s.stream_type()} format:{s.format()}') | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyrealsense2 as rs | |
from pprint import pprint | |
from collections import namedtuple | |
from functools import partial | |
attrs = [ | |
'acceleration', | |
'angular_acceleration', | |
'angular_velocity', | |
'mapper_confidence', | |
'rotation', | |
'tracker_confidence', | |
'translation', | |
'velocity', | |
] | |
Pose = namedtuple('Pose', attrs) | |
def main(): | |
pipeline = rs.pipeline() | |
cfg = rs.config() | |
# if only pose stream is enabled, fps is higher (202 vs 30) | |
cfg.enable_stream(rs.stream.pose) | |
pipeline.start(cfg) | |
poses = [] | |
try: | |
while True: | |
frames = pipeline.wait_for_frames() | |
pose_frame = frames.get_pose_frame() | |
if pose_frame: | |
pose = pose_frame.get_pose_data() | |
n = pose_frame.get_frame_number() | |
timestamp = pose_frame.get_timestamp() | |
p = Pose(*map(partial(getattr, pose), attrs)) | |
poses.append((n, timestamp, p)) | |
if len(poses) == 100: | |
return | |
finally: | |
pipeline.stop() | |
duration = (poses[-1][1]-poses[0][1])/1000 | |
print(f'start: {poses[0][1]}') | |
print(f'end: {poses[-1][1]}') | |
print(f'duration: {duration}s') | |
print(f'fps: {len(poses)/duration}') | |
if __name__ == "__main__": | |
main() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyrealsense2 as rs | |
import numpy as np | |
import cv2 | |
def main(): | |
pipeline = rs.pipeline() | |
pipeline.start() | |
try: | |
while True: | |
frames = pipeline.wait_for_frames() | |
f1 = frames.get_fisheye_frame(1) | |
f2 = frames.get_fisheye_frame(2) | |
if not f1: | |
continue | |
assert f1 and f2 | |
image1 = np.asanyarray(f1.get_data()) | |
image2 = np.asanyarray(f2.get_data()) | |
images = np.hstack((image1, image2)) | |
cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE) | |
cv2.imshow('RealSense', images) | |
key = cv2.waitKey(1) | |
if key == 27: # ESC | |
return | |
if key == ord('s'): | |
cv2.imwrite("a.jpg", images) | |
finally: | |
pipeline.stop() | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment