OpenCV 支持
OpenCV 支持
ColorCamera 节点来检索交错的 BGR 'preview' 和编码为 NV12 的 'video' 帧。 两者都使用 getFrame 和 getCvFrame 函数进行显示。演示
设置
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py源代码
Python
PythonGitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5
6# Create pipeline
7pipeline = dai.Pipeline()
8
9# Define source and outputs
10camRgb = pipeline.create(dai.node.ColorCamera)
11xoutVideo = pipeline.create(dai.node.XLinkOut)
12xoutPreview = pipeline.create(dai.node.XLinkOut)
13
14xoutVideo.setStreamName("video")
15xoutPreview.setStreamName("preview")
16
17# Properties
18camRgb.setPreviewSize(300, 300)
19camRgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
20camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
21camRgb.setInterleaved(True)
22camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.BGR)
23
24# Linking
25camRgb.video.link(xoutVideo.input)
26camRgb.preview.link(xoutPreview.input)
27
28# Connect to device and start pipeline
29with dai.Device(pipeline) as device:
30
31 video = device.getOutputQueue('video')
32 preview = device.getOutputQueue('preview')
33
34 while True:
35 videoFrame = video.get()
36 previewFrame = preview.get()
37
38 # Get BGR frame from NV12 encoded video frame to show with opencv
39 cv2.imshow("video", videoFrame.getCvFrame())
40 # Show 'preview' frame as is (already in correct format, no copy is made)
41 cv2.imshow("preview", previewFrame.getFrame())
42
43 if cv2.waitKey(1) == ord('q'):
44 breakPipeline
需要帮助?
请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。