Created
October 2, 2023 17:45
-
-
Save Erol444/88690739d09cadb3c193894c549a2833 to your computer and use it in GitHub Desktop.
DepthAI OAK stop/start video streaming from ColorCamera node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import depthai as dai | |
import cv2 | |
# Create pipeline | |
pipeline = dai.Pipeline() | |
# Define sources and outputs | |
camRgb = pipeline.create(dai.node.ColorCamera) | |
controlIn = pipeline.create(dai.node.XLinkIn) | |
controlIn.setStreamName('control') | |
controlIn.out.link(camRgb.inputControl) | |
# Linking | |
ispOut = pipeline.create(dai.node.XLinkOut) | |
ispOut.setStreamName('isp') | |
camRgb.isp.link(ispOut.input) | |
# Connect to device and start pipeline | |
with dai.Device(pipeline) as device: | |
controlQueue = device.getInputQueue('control') | |
ispQueue = device.getOutputQueue('isp') | |
while True: | |
vidFrames = ispQueue.tryGetAll() | |
for vidFrame in vidFrames: | |
cv2.imshow('video', vidFrame.getCvFrame()) | |
# Update screen (1ms pooling rate) | |
key = cv2.waitKey(1) | |
if key == ord('q'): | |
break | |
elif key == ord('s'): | |
print("setStopStreaming") | |
ctrl = dai.CameraControl() | |
ctrl.setStopStreaming() | |
ctrl.setAutoFocusMode(dai.CameraControl.AutoFocusMode.CONTINUOUS_VIDEO) | |
controlQueue.send(ctrl) | |
elif key == ord('c'): | |
print("Continue streaming") | |
ctrl = dai.CameraControl() | |
ctrl.setStartStreaming() | |
ctrl.setAutoFocusMode(dai.CameraControl.AutoFocusMode.CONTINUOUS_VIDEO) | |
controlQueue.send(ctrl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment