1 Star 3 Fork 4

OAKChina/depthai-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
device_queue_event.py 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env python3
"""
This example demonstrates use of queue events to block a thread until a message
arrives to any (of the specified) queue
"""
import cv2
import depthai as dai
# Create pipeline
pipeline = dai.Pipeline()
# Define sources and outputs
camRgb = pipeline.create(dai.node.ColorCamera)
camMono = pipeline.create(dai.node.MonoCamera)
xoutRgb = pipeline.create(dai.node.XLinkOut)
xoutMono = pipeline.create(dai.node.XLinkOut)
xoutRgb.setStreamName("rgb")
xoutMono.setStreamName("mono")
# Properties
camRgb.setInterleaved(True)
camRgb.setPreviewSize(300, 300)
# Linking
camRgb.preview.link(xoutRgb.input)
camMono.out.link(xoutMono.input)
# Connect to device and start pipeline
with dai.Device(pipeline) as device:
# Clear queue events
device.getQueueEvents()
while True:
# Block until a message arrives to any of the specified queues
queueName = device.getQueueEvent(("rgb", "mono"))
# Getting that message from queue with name specified by the event
# Note: number of events doesn't necessarily match number of messages in queues
# because queues can be set to non-blocking (overwriting) behavior
message = device.getOutputQueue(queueName).get()
# Display arrived frames
if type(message) == dai.ImgFrame:
cv2.imshow(queueName, message.getCvFrame())
if cv2.waitKey(1) == ord('q'):
break
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/oakchina/depthai-python.git
git@gitee.com:oakchina/depthai-python.git
oakchina
depthai-python
depthai-python
main

搜索帮助