DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • RGB Preview
  • Similar samples:
  • Demo
  • Setup
  • Source code
  • Pipeline

RGB Preview

This example shows how to set up a pipeline that outputs a small preview of the RGB camera, connects over XLink to transfer these to the host real-time, and displays the RGB frames on the host with OpenCV.Note that preview frames are not suited for larger resolution (eg. 1920x1080). Preview is more suitable for either NN or visualization purposes. Please check out ColorCamera node to get a better view.If you want to get higher resolution RGB frames sample please visit RGB video.

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

Python
GitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5
6# Create pipeline
7pipeline = dai.Pipeline()
8
9# Define source and output
10camRgb = pipeline.create(dai.node.ColorCamera)
11xoutRgb = pipeline.create(dai.node.XLinkOut)
12
13xoutRgb.setStreamName("rgb")
14
15# Properties
16camRgb.setPreviewSize(300, 300)
17camRgb.setInterleaved(False)
18camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.RGB)
19
20# Linking
21camRgb.preview.link(xoutRgb.input)
22
23# Connect to device and start pipeline
24with dai.Device(pipeline) as device:
25
26    print('Connected cameras:', device.getConnectedCameraFeatures())
27    # Print out usb speed
28    print('Usb speed:', device.getUsbSpeed().name)
29    # Bootloader version
30    if device.getBootloaderVersion() is not None:
31        print('Bootloader version:', device.getBootloaderVersion())
32    # Device name
33    print('Device name:', device.getDeviceName(), ' Product name:', device.getProductName())
34
35    # Output queue will be used to get the rgb frames from the output defined above
36    qRgb = device.getOutputQueue(name="rgb", maxSize=4, blocking=False)
37
38    while True:
39        inRgb = qRgb.get()  # blocking call, will wait until a new data has arrived
40
41        # Retrieve 'bgr' (opencv format) frame
42        cv2.imshow("rgb", inRgb.getCvFrame())
43
44        if cv2.waitKey(1) == ord('q'):
45            break

Pipeline

Need assistance?

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