Skip to content

Instantly share code, notes, and snippets.

@Erol444
Last active November 2, 2024 12:44
Show Gist options
  • Save Erol444/312960ddec880bd2939ab0a7df76111e to your computer and use it in GitHub Desktop.
Save Erol444/312960ddec880bd2939ab0a7df76111e to your computer and use it in GitHub Desktop.
Strobe demo with OAK-D-Pro-PoE
#!/usr/bin/env python3
from datetime import timedelta
import cv2
import depthai as dai
# Create pipeline
pipeline = dai.Pipeline()
FPS = 30
monoLeft = pipeline.create(dai.node.MonoCamera)
monoLeft.setFps(FPS)
monoLeft.setCamera("left")
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_800_P)
monoLeft.initialControl.setManualExposure(200, 200)
monoRight = pipeline.create(dai.node.MonoCamera)
monoRight.setCamera("right")
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_800_P)
monoRight.initialControl.setManualExposure(200, 200)
monoRight.setFps(FPS)
colorCam = pipeline.create(dai.node.ColorCamera)
colorCam.setBoardSocket(dai.CameraBoardSocket.RGB)
colorCam.setResolution(dai.ColorCameraProperties.SensorResolution.THE_2024X1520)
colorCam.setIspScale(1,2)
colorCam.initialControl.setManualExposure(1000,300)
colorCam.setFps(FPS)
# Properties
config = dai.Device.Config()
config.board.gpio[6] = dai.BoardConfig.GPIO(
dai.BoardConfig.GPIO.OUTPUT, dai.BoardConfig.GPIO.Level.HIGH,
)
config.board.gpio[52] = dai.BoardConfig.GPIO(
dai.BoardConfig.GPIO.OUTPUT, dai.BoardConfig.GPIO.Level.HIGH,
)
sync = pipeline.create(dai.node.Sync)
sync.setSyncThreshold(timedelta(milliseconds=500//FPS))
monoLeft.out.link(sync.inputs['left'])
monoRight.out.link(sync.inputs['right'])
colorCam.video.link(sync.inputs['color'])
# Linking
xout = pipeline.create(dai.node.XLinkOut)
xout.setStreamName('sync')
sync.out.link(xout.input)
# Connect to device and start pipeline
with dai.Device(config) as device:
device.startPipeline(pipeline)
q = device.getOutputQueue(name="sync", maxSize=4, blocking=False)
while True:
msgs = q.get()
def show(name: str, img: dai.ImgFrame):
frame = img.getCvFrame()
exposure = img.getExposureTime().total_seconds() * 1e6
iso = img.getSensitivity()
# Write exposure, iso to the frame
frame = cv2.putText(frame, f"Exp: {exposure:.2f} us", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2, cv2.LINE_AA)
frame = cv2.putText(frame, f"ISO: {iso}", (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2, cv2.LINE_AA)
cv2.imshow(name, frame)
show('left', msgs['left'])
show('right', msgs['right'])
show('color', msgs['color'])
key = cv2.waitKey(1)
if key == ord('q'):
break
if key == ord('c'):
# Save all frames
cv2.imwrite('left.png', msgs['left'].getCvFrame())
cv2.imwrite('right.png', msgs['right'].getCvFrame())
cv2.imwrite('color.png', msgs['color'].getCvFrame())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment