Created
June 1, 2024 10:32
-
-
Save Erol444/54f8b8305d8c16599f09dbb3c5a30d84 to your computer and use it in GitHub Desktop.
OAK-1-MAX 32MP still and video stream
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 | |
pipeline = dai.Pipeline() | |
# Define a source - color camera | |
cam = pipeline.create(dai.node.ColorCamera) | |
cam.setResolution(dai.ColorCameraProperties.SensorResolution.THE_5312X6000) # 32MP for still images | |
cam.setNumFramesPool(2,2,1,1,1) # Can't put 2,2,0,0,0 -> it'll crash | |
cam.setImageOrientation(dai.CameraImageOrientation.VERTICAL_FLIP) | |
cam.setVideoSize(100,100) # Reduce RAM | |
cam.setPreviewSize(100,100) # Reduce RAM | |
cam.setFps(10) | |
NEW_WIDTH = 1328 | |
NEW_HEIGHT = 1500 | |
# ------ Video Streaming ------ | |
downscale_manip = pipeline.create(dai.node.ImageManip) # Downscale to 1/4 size | |
downscale_manip.initialConfig.setCenterCrop(1, 0.77) | |
downscale_manip.initialConfig.setKeepAspectRatio(False) | |
downscale_manip.initialConfig.setResize(NEW_WIDTH, NEW_HEIGHT) | |
downscale_manip.setNumFramesPool(2) | |
downscale_manip.setMaxOutputFrameSize(10581504) # 1.5 is for NV12 - 1.5 bytes per pixel | |
cam.isp.link(downscale_manip.inputImage) | |
vide_xout = pipeline.create(dai.node.XLinkOut) | |
vide_xout.setStreamName('stream') | |
downscale_manip.out.link(vide_xout.input) | |
# ------ Still Image ------q | |
xin = pipeline.create(dai.node.XLinkIn) | |
xin.setMaxDataSize(100) | |
xin.setStreamName('cam_control') # For taking photo & config | |
xin.out.link(cam.inputControl) | |
still_xout = pipeline.create(dai.node.XLinkOut) | |
still_xout.setStreamName('still') | |
cam.still.link(still_xout.input) | |
# config.board.sippDmaBufferSize = 10*1024 | |
pipeline.setSippBufferSize(14 * 1024) | |
pipeline.setSippDmaBufferSize(10 * 1024) | |
with dai.Device(pipeline) as device: | |
streamQ = device.getOutputQueue(name="stream", maxSize=2, blocking=False) | |
stillQueue = device.getOutputQueue(name="still", maxSize=1, blocking=False) | |
xinQueue = device.getInputQueue(name="cam_control") | |
while True: | |
if streamQ.has(): | |
downscaled = streamQ.get().getCvFrame() | |
cv2.imshow('stream', cv2.rotate(downscaled, cv2.ROTATE_90_CLOCKWISE)) | |
if stillQueue.has(): | |
img = stillQueue.get().getCvFrame() | |
rotated = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE) | |
# Save img | |
cv2.imwrite('still.jpg', rotated) | |
cv2.imshow('still', rotated) | |
key = cv2.waitKey(1) | |
if key == ord('q'): | |
break | |
elif key == ord('c'): | |
xinQueue.send(dai.CameraControl().setCaptureStill(True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment