Skip to content

Instantly share code, notes, and snippets.

@Erol444
Created October 2, 2023 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Erol444/88690739d09cadb3c193894c549a2833 to your computer and use it in GitHub Desktop.
Save Erol444/88690739d09cadb3c193894c549a2833 to your computer and use it in GitHub Desktop.
DepthAI OAK stop/start video streaming from ColorCamera node
#!/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