I managed to get it to start (following the linked code), modifying and readjusting so that I can also have the distance of the object recognized, but now I am facing another problem, after a total of about 50 seconds(since I run host.py) it seems that it fills up the RAM? or at any rate the CPU of the camera (OAK PoE) cannot handle the load and it is as if it resets, in fact after a few seconds it redoes the “click” and starts again.
By lowering the fps I have achieved almost 60s but still little I need an “almost infinite autonomy” at least as long as the camera is attached
`import depthai as dai
import time
import blobconverter
FLASH_APP = True
pipeline = dai.Pipeline()
Define sources and outputs
camRgb = pipeline.create(dai.node.ColorCamera)
#spatialDetectionNetwork = pipeline.create(dai.node.MobileNetSpatialDetectionNetwork)
spatialDetectionNetwork = pipeline.create(dai.node.YoloSpatialDetectionNetwork)
monoLeft = pipeline.create(dai.node.MonoCamera)
monoRight = pipeline.create(dai.node.MonoCamera)
stereo = pipeline.create(dai.node.StereoDepth)
Properties
camRgb.setPreviewSize(640, 352)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
camRgb.setInterleaved(False)
camRgb.setFps(40)
camRgb.setPreviewKeepAspectRatio(False)
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
monoLeft.setCamera("left")
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
monoRight.setCamera("right")
#stereo.setDepthAlign(dai.CameraBoardSocket.CAM_A)
stereo.setOutputSize(monoLeft.getResolutionWidth(), monoLeft.getResolutionHeight())
stereo.setSubpixel(True)
#nnBlobPath = "mobilenet-ssd_openvino_2021.4_5shave.blob"
Network specific settings
spatialDetectionNetwork.setBlobPath(blobconverter.from_zoo('yolov8n_coco_640x352', zoo_type='depthai'))
#spatialDetectionNetwork.setBlobPath(nnBlobPath)
spatialDetectionNetwork.setConfidenceThreshold(0.5)
spatialDetectionNetwork.input.setBlocking(False)
spatialDetectionNetwork.setBoundingBoxScaleFactor(0.5)
spatialDetectionNetwork.setDepthLowerThreshold(100)
spatialDetectionNetwork.setDepthUpperThreshold(5000)
Yolo specific parameters
spatialDetectionNetwork.setNumClasses(80)
spatialDetectionNetwork.setCoordinateSize(4)
spatialDetectionNetwork.setAnchors([10,14, 23,27, 37,58, 81,82, 135,169, 344,319])
spatialDetectionNetwork.setAnchorMasks({ "side26": [1,2,3], "side13": [3,4,5] })
spatialDetectionNetwork.setIouThreshold(0.5)
Linking
monoLeft.out.link(stereo.left)
monoRight.out.link(stereo.right)
camRgb.preview.link(spatialDetectionNetwork.input)
Create Script node that will handle TCP communication
script = pipeline.create(dai.node.Script)
script.setProcessor(dai.ProcessorType.LEON_CSS)
Link outputs (RGB stream, NN output) to the Script node
stereo.depth.link(spatialDetectionNetwork.inputDepth)
spatialDetectionNetwork.passthrough.link(script.inputs['frame_in'])
spatialDetectionNetwork.out.link(script.inputs['detection_in'])
script.setScript("""
import socket
import time
import threading
node.warn("Server up")
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(("0.0.0.0", 5000))
server.listen()
while True:
conn, client = server.accept()
node.warn(f"Connected to client IP: {client}")
try:
while True:
detections = node.io["detection_in"].get().detections
img = node.io["frame_in"].get()
node.warn('Received frame + dets')
img_data = img.getData()
ts = img.getTimestamp()
det_arr = []
for det in detections:
det_arr.append(f"{det.label};{(det.confidence*100):.1f};{det.spatialCoordinates.z};{det.xmin:.4f};{det.ymin:.4f};{det.xmax:.4f};{det.ymax:.4f}")
det_str = "|".join(det_arr)
header = f"IMG {ts.total_seconds()} {len(img_data)} {len(det_str)}".ljust(32)
node.warn(f'>{header}<')
conn.send(bytes(header, encoding='ascii'))
if 0 < len(det_arr):
conn.send(bytes(det_str, encoding='ascii'))
conn.send(img_data)
except Exception as e:
node.warn("Client disconnected")
""")
if FLASH_APP: # flash the app for Standalone mode
(f, bl) = dai.DeviceBootloader.getFirstAvailableDevice()
bootloader = dai.DeviceBootloader(bl)
progress = lambda p : print(f'Flashing progress: {p*100:.1f}%')
bootloader.flash(progress, pipeline)
else: # Run the app in peripheral mode
with dai.Device(pipeline) as device:
print("Connected")
while True:
time.sleep(1)`
@jakaskerl do you have any idea what could be the reason? i also already tried with other .blobs but it changes by a few seconds