-
-
Save darkseed/6be195b0bddb244088be0a0906897d95 to your computer and use it in GitHub Desktop.
NDVI camera - switchable IR filter with Luxonis' OAK-FFC-4P and Arducam's IMX477
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() | |
camA = pipeline.createColorCamera() | |
camA.setBoardSocket(dai.CameraBoardSocket.CAM_A) | |
camA.setResolution(dai.ColorCameraProperties.SensorResolution.THE_12_MP) | |
script = pipeline.create(dai.node.Script) | |
# To send switch command to IR filter | |
xin = pipeline.create(dai.node.XLinkIn) | |
xin.setStreamName('in') | |
xin.out.link(script.inputs['in']) | |
script.setScript(""" | |
import GPIO | |
MX_PIN = 40 # OAK-FFC-4P R5 | |
toggleVal = True | |
GPIO.setup(MX_PIN, GPIO.OUT, GPIO.PULL_DOWN) | |
GPIO.write(MX_PIN, toggleVal) | |
while True: | |
data = node.io['in'].get() | |
node.warn('GPIO toggle: ' + str(toggleVal)) | |
toggleVal = not toggleVal | |
GPIO.write(MX_PIN, toggleVal) | |
""") | |
xoutA = pipeline.create(dai.node.XLinkOut) | |
xoutA.setStreamName('cam_a') | |
camA.isp.link(xoutA.input) | |
import time | |
# Connect to device with pipeline | |
with dai.Device(pipeline) as device: | |
inQ = device.getInputQueue("in") | |
q = device.getOutputQueue("cam_a") | |
def send_trigger(): | |
inQ.send(dai.Buffer()) | |
capture = False | |
while True: | |
if q.has(): | |
frame: dai.ImgFrame = q.get() | |
frame = frame.getCvFrame() | |
cv2.imshow('Color', frame) | |
if capture: | |
cv2.imwrite(f'frame.png', frame) | |
capture = False | |
key = cv2.waitKey(1) | |
if key == ord('q'): # Quit the program | |
break | |
if key == ord('c'): # Capture the image | |
capture = True | |
elif key == ord('t'): # Switch IR filter | |
print('send trigger to IR filter') | |
send_trigger() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment