Created
November 21, 2022 10:34
-
-
Save Erol444/a9189a8215371ff9f4cf4472960e1d66 to your computer and use it in GitHub Desktop.
Luxonis OAK camera trigger FSYNC pin via Script node for DM9098 board (OAK-D S2/Pro/W/Pro W)
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
#!/usr/bin/env python3 | |
import depthai as dai | |
import cv2 | |
import time | |
pipeline = dai.Pipeline() | |
camRgb = pipeline.create(dai.node.ColorCamera) | |
camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.RGB) | |
camRgb.setIspScale(2,3) | |
camRgb.initialControl.setFrameSyncMode(dai.CameraControl.FrameSyncMode.INPUT) | |
camRgb.initialControl.setExternalTrigger(4,3) | |
xoutRgb = pipeline.create(dai.node.XLinkOut) | |
xoutRgb.setStreamName("color") | |
camRgb.isp.link(xoutRgb.input) | |
monoLeft = pipeline.create(dai.node.MonoCamera) | |
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P) | |
monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT) | |
monoLeft.initialControl.setFrameSyncMode(dai.CameraControl.FrameSyncMode.INPUT) | |
monoLeft.initialControl.setExternalTrigger(4,3) | |
xoutLeft = pipeline.create(dai.node.XLinkOut) | |
xoutLeft.setStreamName("left") | |
monoLeft.out.link(xoutLeft.input) | |
monoRight = pipeline.createMonoCamera() | |
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P) | |
monoRight.setBoardSocket(dai.CameraBoardSocket.RIGHT) | |
monoRight.initialControl.setFrameSyncMode(dai.CameraControl.FrameSyncMode.INPUT) | |
monoRight.initialControl.setExternalTrigger(4,3) | |
xoutRight = pipeline.create(dai.node.XLinkOut) | |
xoutRight.setStreamName("right") | |
monoRight.out.link(xoutRight.input) | |
xin = pipeline.create(dai.node.XLinkIn) | |
xin.setStreamName('in') | |
script = pipeline.create(dai.node.Script) | |
xin.out.link(script.inputs['in']) | |
script.setScript(""" | |
import GPIO | |
import time | |
GPIO_PIN=41 # Trigger | |
GPIO.setup(GPIO_PIN, GPIO.OUT, GPIO.PULL_DOWN) | |
def capture(): | |
GPIO.write(GPIO_PIN, True) | |
time.sleep(0.001) # 1ms pulse is enough | |
GPIO.write(GPIO_PIN, False) | |
while True: | |
wait_for_trigger = node.io['in'].get() | |
capture() | |
node.warn('Trigger successful') | |
""") | |
xout = pipeline.create(dai.node.XLinkOut) | |
xout.setStreamName('out') | |
script.outputs['out'].link(xout.input) | |
# Connect to device with pipeline | |
with dai.Device(pipeline) as device: | |
inQ = device.getInputQueue("in") | |
arr = ['left', 'right', 'color'] | |
queues = {} | |
frames = {} | |
for name in arr: | |
queues[name] = device.getOutputQueue(name) | |
def trigger(): | |
buffer = dai.Buffer() | |
buffer.setData([1]) | |
inQ.send(buffer) | |
time.sleep(1) | |
trigger() # Inital trigger | |
while True: | |
for name in arr: | |
if queues[name].has(): | |
frames[name]=queues[name].get().getCvFrame() | |
for name, frame in frames.items(): | |
cv2.imshow(name, frame) | |
key = cv2.waitKey(1) | |
if key == ord('q'): | |
break | |
elif key == ord('c'): | |
trigger() |
I tried as well but I also only got images from the left and right cameras, not from the color camera.
python: 3.10
depthai: 2.20.2.0
OAK-D Pro PoE
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried to run the script but I only got images from the
left
andright
cameras, not from thecolor
camera.