DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • Mono Preview
  • Similar samples:
  • Demo
  • Setup
  • Source code

Mono Preview

This example shows how to set up a pipeline that outputs the left and right grayscale camera images, connects over XLink to transfer these to the host real-time, and displays both using OpenCV.

Similar samples:

Demo

Setup

Please run the install script to download all required dependencies. Please note that this script must be ran from git context, so you have to download the depthai-python repository first and then run the script
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
For additional information, please follow the installation guide.

Source code

Python
C++
Python
GitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5
6# Create pipeline
7pipeline = dai.Pipeline()
8
9# Define sources and outputs
10monoLeft = pipeline.create(dai.node.MonoCamera)
11monoRight = pipeline.create(dai.node.MonoCamera)
12xoutLeft = pipeline.create(dai.node.XLinkOut)
13xoutRight = pipeline.create(dai.node.XLinkOut)
14
15xoutLeft.setStreamName('left')
16xoutRight.setStreamName('right')
17
18# Properties
19monoLeft.setCamera("left")
20monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
21monoRight.setCamera("right")
22monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
23
24# Linking
25monoRight.out.link(xoutRight.input)
26monoLeft.out.link(xoutLeft.input)
27
28# Connect to device and start pipeline
29with dai.Device(pipeline) as device:
30
31    # Output queues will be used to get the grayscale frames from the outputs defined above
32    qLeft = device.getOutputQueue(name="left", maxSize=4, blocking=False)
33    qRight = device.getOutputQueue(name="right", maxSize=4, blocking=False)
34
35    while True:
36        # Instead of get (blocking), we use tryGet (non-blocking) which will return the available data or None otherwise
37        inLeft = qLeft.tryGet()
38        inRight = qRight.tryGet()
39
40        if inLeft is not None:
41            cv2.imshow("left", inLeft.getCvFrame())
42
43        if inRight is not None:
44            cv2.imshow("right", inRight.getCvFrame())
45
46        if cv2.waitKey(1) == ord('q'):
47            break

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.