erik oh sorry i missed it in my hurry 🙂
Here's a new version:
from pathlib import Path
import cv2
import depthai as dai
import numpy as np
\# Get argument first
yolo_v5_path = str((Path(__file__).parent / Path('ai_v2/result/best_openvino_2022.1_6shave.blob')).resolve().absolute())
GPIO = dai.BoardConfig.GPIO
\# Define outputs for serial communication
uartNum = 0
uarts = {
0: { # Suitable for the custom TG board
'txPin' : 15,
'rxPin' : 16,
'txPinMode' : GPIO.ALT_MODE_2,
'rxPinMode' : GPIO.ALT_MODE_2,
}
}
\# Start defining a pipeline
pipeline = dai.Pipeline()
pipeline.setOpenVINOVersion(version=dai.OpenVINO.Version.VERSION_2022_1)
pyserial = """
import serial
ser = serial.Serial("/dev/ttyS0", baudrate=115200)
bboxes = []
while True:
in_nn = node.io['detections'].get()
if in_nn is not None:
bboxes = in_nn.detections
if bboxes is not None:
yellowValues = [-1,-1,-1,-1]
blueValues = [-1,-1,-1,-1]
ballValues = [-1,-1,-1,-1]
for bbox in bboxes:
# denormalize bounding box
x1 = int(bbox.xmin \* size)
x2 = int(bbox.xmax \* size)
y1 = int(bbox.ymin \* size)
y2 = int(bbox.ymax \* size)
if check:
coordinates = list()
coordinates.append(x1)
coordinates.append(x2)
coordinates.append(y1)
serString = 'str(ballValues[0])'
ser.write(serString.encode())
"""
\# Define script for output
script = pipeline.create(dai.node.Script)
script.setProcessor(dai.ProcessorType.LEON_CSS)
script.setScript(pyserial)
\# Create output
detectionNetwork.out.link(script.inputs["detections"])
config = dai.Device.Config()
config.board.gpio[uarts[uartNum]['txPin']] = GPIO(GPIO.OUTPUT, uarts[uartNum]['txPinMode'])
config.board.gpio[uarts[uartNum]['rxPin']] = GPIO(GPIO.INPUT, uarts[uartNum]['rxPinMode'])
config.board.uart[uartNum] = dai.BoardConfig.UART()
config.version = config.version.VERSION_2021_4
\# Flash the pipeline
(f, bl) = dai.DeviceBootloader.getFirstAvailableDevice()
bootloader = dai.DeviceBootloader(bl)
progress = lambda p: print(f'Flashing progress: {p \* 100:.1f}%')
bootloader.flash(progress, pipeline)
DetectionNetwork is my network with the blobpath.