diff --git a/opencv_support.py b/opencv_support.py new file mode 100755 index 0000000..c76dd13 --- /dev/null +++ b/opencv_support.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +import cv2 +import depthai as dai + +# Create pipeline +pipeline = dai.Pipeline() + +# Define source and outputs +camRgb = pipeline.createColorCamera() +xoutVideo = pipeline.createXLinkOut() +xoutPreview = pipeline.createXLinkOut() + +xoutVideo.setStreamName("video") +xoutPreview.setStreamName("preview") + +# Properties +camRgb.setPreviewSize(300, 300) +camRgb.setBoardSocket(dai.CameraBoardSocket.RGB) +camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P) +camRgb.setInterleaved(True) +camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.BGR) + +# Linking +camRgb.video.link(xoutVideo.input) +camRgb.preview.link(xoutPreview.input) + +# Connect to device and start pipeline +with dai.Device(pipeline) as device: + + video = device.getOutputQueue('video') + preview = device.getOutputQueue('preview') + + while True: + videoFrame = video.get() + previewFrame = preview.get() + + # Get BGR frame from NV12 encoded video frame to show with opencv + cv2.imshow("video", videoFrame.getCvFrame()) + # Show 'preview' frame as is (already in correct format, no copy is made) + cv2.imshow("preview", previewFrame.getFrame()) + + if cv2.waitKey(1) == ord('q'): + break