how to extract depthdata from video in python

Solutions on MaxInterview for how to extract depthdata from video in python by the best coders in the world

showing results for - "how to extract depthdata from video in python"
Luana
07 Sep 2016
1import pyrealsense2 as rs
2import numpy as np
3import cv2
4
5pipeline = rs.pipeline()
6config = rs.config()
7config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
8config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
9
10color_path = 'V00P00A00C00_rgb.avi'
11depth_path = 'V00P00A00C00_depth.avi'
12colorwriter = cv2.VideoWriter(color_path, cv2.VideoWriter_fourcc(*'XVID'), 30, (640,480), 1)
13depthwriter = cv2.VideoWriter(depth_path, cv2.VideoWriter_fourcc(*'XVID'), 30, (640,480), 1)
14
15pipeline.start(config)
16
17try:
18    while True:
19        frames = pipeline.wait_for_frames()
20        depth_frame = frames.get_depth_frame()
21        color_frame = frames.get_color_frame()
22        if not depth_frame or not color_frame:
23            continue
24        
25        #convert images to numpy arrays
26        depth_image = np.asanyarray(depth_frame.get_data())
27        color_image = np.asanyarray(color_frame.get_data())
28        depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)
29        
30        colorwriter.write(color_image)
31        depthwriter.write(depth_colormap)
32        
33        cv2.imshow('Stream', depth_colormap)
34        
35        if cv2.waitKey(1) == ord("q"):
36            break
37finally:
38    colorwriter.release()
39    depthwriter.release()
40    pipeline.stop()
similar questions