Created
November 26, 2020 15:18
-
-
Save OlegJakushkin/483fd853a52831600ede13848ecb1a16 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
pipeline = rs.pipeline() | |
config = rs.config() | |
config.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 15) | |
config.enable_stream(rs.stream.infrared, 1, 1280, 720, rs.format.y8, 15) | |
config.enable_stream(rs.stream.infrared, 2, 1280, 720, rs.format.y8, 15) | |
#config.enable_stream(rs.stream.infrared1, 640, 480, rs.format.y8, 30) | |
#config.enable_stream(rs.stream.depth, 640, 480, rs.format.y8, 30) | |
color_path = 'V00P00A00C00_infrared1.avi' | |
depth_path = 'V00P00A00C00_depth.avi' | |
colorwriter = cv2.VideoWriter(color_path, cv2.VideoWriter_fourcc(*'XVID'), 15, (1280, 720), 1) | |
depthwriter = cv2.VideoWriter(depth_path, cv2.VideoWriter_fourcc(*'XVID'), 15, (1280, 720), 1) | |
pipeline.start(config) | |
try: | |
integer = 0 | |
targert_integer = 40 | |
while integer < targert_integer: | |
integer += 1 | |
frames = pipeline.wait_for_frames() | |
depth_frame = frames.get_depth_frame() | |
ir1_frame = frames.get_infrared_frame(1) | |
#color_frame = frames.get_color_frame() | |
if not depth_frame or not ir1_frame: | |
continue | |
infrared_img = np.asanyarray(ir1_frame.get_data()) | |
depth_image = np.asanyarray(depth_frame.get_data()) | |
depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET) | |
ir1_image = cv2.cvtColor(infrared_img, cv2.COLOR_GRAY2BGR) | |
colorwriter.write(ir1_image) | |
depthwriter.write(depth_colormap) | |
if cv2.waitKey(1) == ord("q"): | |
break | |
finally: | |
colorwriter.release() | |
depthwriter.release() | |
pipeline.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment