l515.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. ## License: Apache 2.0. See LICENSE file in root directory.
  2. ## Copyright(c) 2015-2017 Intel Corporation. All Rights Reserved.
  3. ###############################################
  4. ## Open CV and Numpy integration ##
  5. ###############################################
  6. import pyrealsense2 as rs
  7. import numpy as np
  8. import cv2
  9. pipeline = rs.pipeline()
  10. config = rs.config()
  11. config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
  12. config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
  13. pipeline.start(config)
  14. try:
  15. while True:
  16. frames = pipeline.wait_for_frames()
  17. depth_frame = frames.get_depth_frame()
  18. color_frame = frames.get_color_frame()
  19. if not depth_frame or not color_frame:
  20. continue
  21. depth_image = np.asanyarray(depth_frame.get_data())
  22. color_image = np.asanyarray(color_frame.get_data())
  23. depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)
  24. images = np.hstack((color_image, depth_colormap))
  25. cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)
  26. cv2.imshow('RealSense', images)
  27. cv2.waitKey(1)
  28. finally:
  29. pipeline.stop()