DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • Device Queue Event
  • Demo
  • Setup
  • Source code
  • Pipeline

Device Queue Event

This example shows how to use getQueueEvent function in order to be notified when one of the packets from selected streams arrive

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
3"""
4 This example demonstrates use of queue events to block a thread until a message
5 arrives to any (of the specified) queue
6"""
7
8import cv2
9import depthai as dai
10
11# Create pipeline
12pipeline = dai.Pipeline()
13
14# Define sources and outputs
15camRgb = pipeline.create(dai.node.ColorCamera)
16camMono = pipeline.create(dai.node.MonoCamera)
17xoutRgb = pipeline.create(dai.node.XLinkOut)
18xoutMono = pipeline.create(dai.node.XLinkOut)
19
20xoutRgb.setStreamName("rgb")
21xoutMono.setStreamName("mono")
22
23# Properties
24camRgb.setInterleaved(True)
25camRgb.setPreviewSize(300, 300)
26
27# Linking
28camRgb.preview.link(xoutRgb.input)
29camMono.out.link(xoutMono.input)
30
31# Connect to device and start pipeline
32with dai.Device(pipeline) as device:
33
34    # Clear queue events
35    device.getQueueEvents()
36
37    while True:
38        # Block until a message arrives to any of the specified queues
39        queueName = device.getQueueEvent(("rgb", "mono"))
40
41        # Getting that message from queue with name specified by the event
42        # Note: number of events doesn't necessarily match number of messages in queues
43        # because queues can be set to non-blocking (overwriting) behavior
44        message = device.getOutputQueue(queueName).get()
45
46        # Display arrived frames
47        if type(message) == dai.ImgFrame:
48            cv2.imshow(queueName, message.getCvFrame())
49
50        if cv2.waitKey(1) == ord('q'):
51            break

Pipeline

Need assistance?

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