Preview manager

PreviewManager is a class that is made to help you with displaying previews / streams from OAK cameras.

Getting started

PreviewManager works hand in hand with the PipelineManager, so before you can use Preview, you will first have to declare and initialize the PipelineManager. But of course you will also have to import both names to use them. If you do not wish to use the PipelineManager you can also create and initialize the pipeline without the help of the manager. PreviewManager is created so that you can use only it seperatly.

 1from depthai_sdk import Previews
 2from depthai_sdk.managers import PipelineManager, PreviewManager
 3import depthai as dai
 4
 5# create pipeline
 6pm = PipelineManager()
 7
 8# creating color source
 9pm.createColorCam(xout=True)
10
11# connecting to the device
12with dai.Device(pm.pipeline) as device:
13    # define configs for above sources
14    pv = PreviewManager(display=[Previews.color.name])
15
16    # create stream queues
17    pv.createQueues(device)
18    while True:
19        # prepare and show streams
20        pv.prepareFrames()
21        pv.showFrames()

As you can see from the above code, we first initialized the pipeline, after that we defined sources from where the pipeline will stream and after that we connected to the device. When the device is connected, we can declare and initialize the PreviewManager and after that we can see the frames as outputs.

Example of use

 1from depthai_sdk import Previews
 2from depthai_sdk.managers import PipelineManager, PreviewManager
 3import depthai as dai
 4import cv2
 5
 6
 7# create pipeline
 8pm = PipelineManager()
 9
10# define sources (color, left, right, depth)
11
12# creating color source
13pm.createColorCam(xout=True)
14pm.createLeftCam(xout=True)
15pm.createRightCam(xout=True)
16pm.createDepth(useDepth=True)
17
18# connecting to the device
19with dai.Device(pm.pipeline) as device:
20    # define configs for above sources
21    pv = PreviewManager(display=[Previews.color.name, Previews.left.name, Previews.right.name, Previews.depth.name])
22
23    # create stream queues
24    pv.createQueues(device)
25
26    while True:
27        # prepare and show streams
28        pv.prepareFrames()
29        pv.showFrames()
30
31        # end program with 'q'
32        if cv2.waitKey(1) == ord('q'):
33            break

In the above example we added a few more sources. Output of the above code should look something like this:

../../_images/camera_previews.png

We get frames from all defined sources.

class depthai_sdk.managers.PreviewManager

Manager class that handles frames and displays them correctly.

frames = {}

Contains name -> frame mapping that can be used to modify specific frames directly

Type

dict

__init__(display=[], nnSource=None, colorMap=None, depthConfig=None, dispMultiplier=2.65625, mouseTracker=False, decode=False, fpsHandler=None, createWindows=True)
Parameters
  • display (list, Optional) – List of depthai_sdk.Previews objects representing the streams to display

  • mouseTracker (bool, Optional) – If set to True, will enable mouse tracker on the preview windows that will display selected pixel value

  • fpsHandler (depthai_sdk.fps.FPSHandler, Optional) – if provided, will use fps handler to modify stream FPS and display it

  • nnSource (str, Optional) – Specifies NN source camera

  • colorMap (cv2 color map, Optional) – Color map applied on the depth frames

  • decode (bool, Optional) – If set to True, will decode the received frames assuming they were encoded with MJPEG encoding

  • dispMultiplier (float, Optional) – Multiplier used for depth <-> disparity calculations (calculated on baseline and focal)

  • depthConfig (depthai.StereoDepthConfig, optional) – Configuration used for depth <-> disparity calculations

  • createWindows (bool, Optional) – If True, will create preview windows using OpenCV (enabled by default)

collectCalibData(device)

Collects calibration data and calculates dispScaleFactor accordingly

Parameters

device (depthai.Device) – Running device instance

createQueues(device, callback=None)

Create output queues for requested preview streams

Parameters
  • device (depthai.Device) – Running device instance

  • callback (func, Optional) – Function that will be executed with preview name once preview window was created

closeQueues()

Closes output queues for requested preview streams

prepareFrames(blocking=False, callback=None)

This function consumes output queues’ packets and parses them to obtain ready to use frames. To convert the frames from packets, this manager uses methods defined in depthai_sdk.previews.PreviewDecoder.

Parameters
  • blocking (bool, Optional) – If set to True, will wait for a packet in each queue to be available

  • callback (func, Optional) – Function that will be executed once packet with frame has arrived

showFrames(callback=None)

Displays stored frame onto preview windows.

Parameters

callback (func, Optional) – Function that will be executed right before cv2.imshow

has(name)

Determines whether manager has a frame assigned to specified preview

Returns

True if contains a frame, False otherwise

Return type

bool

get(name)

Returns a frame assigned to specified preview

Returns

Resolved frame, will default to None if not present

Return type

numpy.ndarray