Disparity encoding
Similar samples:
Demo

Setup
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.pySource code
Python
C++
Python
PythonGitHub
1#!/usr/bin/env python3
2
3import depthai as dai
4
5# NOTE Because we are encoding disparity values, output video will be a gray, and won't have many pixel levels - either 0..95 or 0..190
6
7# Create pipeline
8pipeline = dai.Pipeline()
9
10# Create left/right mono cameras for Stereo depth
11monoLeft = pipeline.create(dai.node.MonoCamera)
12monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
13monoLeft.setCamera("left")
14
15monoRight = pipeline.create(dai.node.MonoCamera)
16monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
17monoRight.setCamera("right")
18
19# Create a node that will produce the depth map
20depth = pipeline.create(dai.node.StereoDepth)
21depth.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
22depth.initialConfig.setMedianFilter(dai.MedianFilter.KERNEL_7x7)
23depth.setLeftRightCheck(False)
24depth.setExtendedDisparity(False)
25# Subpixel disparity is of UINT16 format, which is unsupported by VideoEncoder
26depth.setSubpixel(False)
27monoLeft.out.link(depth.left)
28monoRight.out.link(depth.right)
29
30videoEnc = pipeline.create(dai.node.VideoEncoder)
31# Depth resolution/FPS will be the same as mono resolution/FPS
32videoEnc.setDefaultProfilePreset(monoLeft.getFps(), dai.VideoEncoderProperties.Profile.MJPEG)
33depth.disparity.link(videoEnc.input)
34
35xout = pipeline.create(dai.node.XLinkOut)
36xout.setStreamName("enc")
37videoEnc.bitstream.link(xout.input)
38
39# Connect to device and start pipeline
40with dai.Device(pipeline) as device:
41
42 # Output queue will be used to get the encoded data from the output defined above
43 q = device.getOutputQueue(name="enc")
44
45 # The .h265 file is a raw stream file (not playable yet)
46 with open('disparity.mjpeg', 'wb') as videoFile:
47 print("Press Ctrl+C to stop encoding...")
48 try:
49 while True:
50 videoFile.write(q.get().getData())
51 except KeyboardInterrupt:
52 # Keyboard interrupt (Ctrl + C) detected
53 pass
54
55 print("To view the encoded data, convert the stream file (.mjpeg) into a video file (.mp4) using a command below:")
56 print("ffmpeg -framerate 30 -i disparity.mjpeg -c copy video.mp4")Pipeline
Need assistance?
Head over to Discussion Forum for technical support or any other questions you might have.