Created
August 2, 2022 14:00
-
-
Save Erol444/21465c326fe23bb821a2ce9e391fb3d9 to your computer and use it in GitHub Desktop.
DepthAI rgb preview modified to capture the 300x300 frames when 'c' is pressed
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 cv2 | |
import depthai as dai | |
import time | |
# Create pipeline | |
pipeline = dai.Pipeline() | |
# Define source and output | |
camRgb = pipeline.create(dai.node.ColorCamera) | |
xoutRgb = pipeline.create(dai.node.XLinkOut) | |
xoutRgb.setStreamName("rgb") | |
# Properties | |
camRgb.setPreviewSize(300, 300) | |
camRgb.setInterleaved(False) | |
camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.RGB) | |
# Linking | |
camRgb.preview.link(xoutRgb.input) | |
# Connect to device and start pipeline | |
with dai.Device(pipeline) as device: | |
print('Connected cameras: ', device.getConnectedCameras()) | |
# Print out usb speed | |
print('Usb speed: ', device.getUsbSpeed().name) | |
# Output queue will be used to get the rgb frames from the output defined above | |
qRgb = device.getOutputQueue(name="rgb", maxSize=4, blocking=False) | |
while True: | |
frame = qRgb.get().getCvFrame() # blocking call, will wait until a new data has arrived | |
# Retrieve 'bgr' (opencv format) frame | |
cv2.imshow("rgb", frame) | |
key = cv2.waitKey(1) | |
if key == ord('q'): | |
break | |
elif key == ord('c'): | |
file = f'{int(time.time() * 1000)}.png' | |
cv2.imwrite(file, frame) | |
print('Saved 300x300 frame to', file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment