Created
July 31, 2021 03:33
-
-
Save lucasmediaflow/2dab67d5528aea2284a62c40e42ec6fc to your computer and use it in GitHub Desktop.
This file contains 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
from gpiozero import LED | |
import depthai as dai | |
import cv2 | |
from time import sleep | |
flashpin = LED(23) | |
pipeline = dai.Pipeline() | |
pipeline.setCameraTuningBlobPath('/home/pi/oak/tuning_color_low_light.bin') | |
camera = pipeline.createColorCamera() | |
# camera.setResolution(dai.ColorCameraProperties.SensorResolution.THE_12_MP) | |
camera.setPreviewSize(300, 300) | |
camera.setInterleaved(False) | |
camera.setFps(1) | |
camera.setPreviewKeepAspectRatio(False) | |
camera.initialControl.setManualFocus(135) | |
camera.initialControl.setAutoFocusMode(dai.RawCameraControl.AutoFocusMode.OFF) | |
jpgEncoder = pipeline.createVideoEncoder() | |
jpgEncoder.setDefaultProfilePreset(camera.getStillSize(), 1, dai.VideoEncoderProperties.Profile.MJPEG) | |
jpgEncoderXLinkOut = pipeline.createXLinkOut() | |
jpgEncoderXLinkOut.setStreamName('jpg') | |
camControl = pipeline.createXLinkIn() | |
camControl.setStreamName('camControl') | |
camera.still.link(jpgEncoder.input) | |
jpgEncoder.bitstream.link(jpgEncoderXLinkOut.input) | |
camControl.out.link(camera.inputControl) | |
def triggerflash(): | |
print('trigger flash') | |
flashpin.on() | |
sleep(0.1) | |
flashpin.off() | |
with dai.Device(pipeline) as dev: | |
camControlQ = dev.getInputQueue('camControl', maxSize = 1, blocking = False) | |
jpgQ = dev.getOutputQueue('jpg', maxSize = 1, blocking = False) | |
ctrl = dai.CameraControl() | |
ctrl.setManualExposure(400000, 100) | |
ctrl.setAutoWhiteBalanceMode( dai.RawCameraControl.AutoWhiteBalanceMode.INCANDESCENT) | |
camControlQ.send(ctrl) | |
frame = None | |
while True: | |
for jpgFrame in jpgQ.tryGetAll(): | |
frame = cv2.imdecode(jpgFrame.getData(), cv2.IMREAD_UNCHANGED) | |
cv2.imshow('aasdf', frame) | |
logo = cv2.imread('/home/pi/logo.png') | |
cv2.imshow('logo', logo) | |
key = cv2.waitKey(1) | |
if key == ord('q'): | |
print('quitting') | |
break | |
elif key == ord('c'): | |
ctrl.setCaptureStill(True) | |
camControlQ.send(ctrl) | |
sleep(0.07) | |
triggerflash() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment