Created
November 12, 2022 03:22
-
-
Save Erol444/fbbb1c7490b09dd942657950003e67d2 to your computer and use it in GitHub Desktop.
DepthAI OAK ColorCamera still capture
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 | |
import time | |
pipeline = dai.Pipeline() | |
# Define sources and outputs | |
camRgb = pipeline.create(dai.node.ColorCamera) | |
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P) | |
camRgb.setIspScale(2,3) # 1080P -> 720P | |
controlIn = pipeline.create(dai.node.XLinkIn) | |
controlIn.setStreamName('control') | |
controlIn.out.link(camRgb.inputControl) | |
# We use Script node to query frame from ColorCamera - this allows 3A algos to run continuosly, | |
# as opposed to only when the still is captured | |
script = pipeline.create(dai.node.Script) | |
script.setScript(""" | |
while True: | |
node.io['preview'].get() # Discard image after the get() | |
""") | |
camRgb.preview.link(script.inputs['preview']) | |
xout = pipeline.create(dai.node.XLinkOut) | |
xout.setStreamName('out') | |
camRgb.still.link(xout.input) | |
with dai.Device(pipeline) as device: | |
# Get data queues | |
controlQ = device.getInputQueue('control') | |
stillQ = device.getOutputQueue('out') | |
def capture(): | |
ctrl = dai.CameraControl() | |
ctrl.setCaptureStill(True) | |
controlQ.send(ctrl) | |
time.sleep(1) # For 3A algos to run | |
capture() | |
frame = stillQ.get().getCvFrame() # Initial frame | |
while True: | |
if stillQ.has(): | |
# Get the frame after capture() was called | |
frame = stillQ.get().getCvFrame() | |
cv2.imshow('Still', frame) | |
key = cv2.waitKey(1) | |
if key == ord('q'): | |
break | |
elif key == ord('c'): | |
# Capture a new frame - you could call this function from within your app | |
capture() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment