Hello ,

I am a student from Taiwan,I have the Oak-d Pro camera an I want to use it to use Object Detection by YOLOv8,after reference sample program, Change the RGBcam to IRcam ,The error show that the Input image (1280x720) does not match NN (640x640) ,but the monoL.setPreviewSize(640, 640) doesn't work,please tell me how to resize it

thanks,li

Hello @jakaskerl

The example code really helps me a lot ,Thank you,After modify my mode,It works,but the output frame is continuously change frame size from 320x320 to much bigger frame size and to 320x320,I don't know where I setting wrong,Can you help me check my code.

import cv2

import depthai as dai

import numpy as np

model_weights_path = "C:/catdog320.blob"
custom_model_blob = dai.OpenVINO.Blob(model_weights_path)

numClasses = 80

dim = next(iter(custom_model_blob.networkInputs.values())).dims
output_name, output_tenser = next(iter(custom_model_blob.networkOutputs.items()))

if "yolov6" in output_name:

    numClasses = output_tenser.dims[2] - 5

else:

    numClasses = output_tenser.dims[2] // 3 - 5
labelMap = [    "class_%s" % i

    for i in range(numClasses)]

pipeline = dai.Pipeline()

monoL = pipeline.create(dai.node.MonoCamera)

manip = pipeline.create(dai.node.ImageManip)

manipOut = pipeline.create(dai.node.XLinkOut)

detectionNetwork = pipeline.create(dai.node.YoloDetectionNetwork)

monoL.setNumFramesPool(24)

xoutNN = pipeline.create(dai.node.XLinkOut)

manipOut.setStreamName('flood-left')

xoutNN.setStreamName("nn")

# Script node for frame routing and IR dot/flood alternate

script = pipeline.create(dai.node.Script)

script.setProcessor(dai.ProcessorType.LEON_CSS)

script.setScript("""

    dotBright = 0.8

    floodBright = 0.1

    LOGGING = False  # Set True for latency/timings debugging
    node.warn(f'IR drivers detected: {str(Device.getIrDrivers())}')
    flagDot = False

    while True:        # Wait first for a frame event, received at MIPI start-of-frame        event = node.io['event'].get()

if LOGGING: tEvent = Clock.now()
  # Immediately reconfigure the IR driver.        # Note the logic is inverted, as it applies for next frame       

Device.setIrLaserDotProjectorIntensity(0 if flagDot else dotBright)       

Device.setIrFloodLightIntensity(floodBright if flagDot else 0)       

if LOGGING: tIrSet = Clock.now()
      # Wait for the actual frame (after MIPI capture and ISP proc is done) 

    frameL = node.io['frameL'].get()       

if LOGGING: tLeft = Clock.now()
    if LOGGING:

latIR      = (tIrSet - tEvent               ).total_seconds() * 1000   

    latEv      = (tEvent - event.getTimestamp() ).total_seconds() * 1000           

latProcL   = (tLeft  - event.getTimestamp() ).total_seconds() * 1000   

      node.warn(f'T[ms] latEv:{latEv:5.3f} latIR:{latIR:5.3f} latProcL:{latProcL:6.3f}')
      if not flagDot:            node.io['floodL'].send(frameL)
        flagDot = not flagDot""")

detectionNetwork.setBlob(custom_model_blob)

detectionNetwork.setConfidenceThreshold(0.4)
detectionNetwork.setNumClasses(numClasses)

detectionNetwork.setCoordinateSize(4)

detectionNetwork.setAnchors([])

detectionNetwork.setAnchorMasks({})

detectionNetwork.setIouThreshold(0.5)

detectionNetwork.input.setBlocking(False)
manip.initialConfig.setResize(320, 320)

manip.initialConfig.setFrameType(dai.ImgFrame.Type.BGR888p)

monoL.out.link(manip.inputImage)

manip.out.link(detectionNetwork.input)

manip.out.link(manipOut.input)

detectionNetwork.out.link(xoutNN.input)

monoL.frameEvent.link(script.inputs['event'])

monoL.out.link(script.inputs['frameL'])

script.outputs['floodL'].link(manipOut .input)

# Connect to device and start pipeline

with dai.Device(pipeline) as device:

    qRight = device.getOutputQueue("flood-left", maxSize=4, blocking=False)

    qDet = device.getOutputQueue("nn", maxSize=4, blocking=False)
    frame = None

    detections = []
    def frameNorm(frame, bbox): 

    normVals = np.full(len(bbox), frame.shape[0])   

    normVals[::2] = frame.shape[1]     

  return (np.clip(np.array(bbox), 0, 1) * normVals).astype(int)
    def drawText(frame, text, org, color=(255, 255, 255), thickness=1):

        cv2.putText(frame, text, org, cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), thickness + 3, cv2.LINE_AA) 

      cv2.putText(frame, text, org, cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, thickness, cv2.LINE_AA        )

def drawRect(frame, topLeft, bottomRight, color=(255, 255, 255), thickness=1):       

cv2.rectangle(frame, topLeft, bottomRight, (0, 0, 0), thickness + 3)   

    cv2.rectangle(frame, topLeft, bottomRight, color, thickness)

def displayFrame(name, frame): 

      color = (128, 128, 128)     

  for detection in detections:     

      bbox = frameNorm(frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax) )            drawText( frame=frame, text=labelMap[detection.label],  org=(bbox[0] + 10, bbox[1] + 20), )            drawText(frame=frame,  text=f"{detection.confidence:.2%}", org=(bbox[0] + 10, bbox[1] + 35),)            drawRect(frame=frame,topLeft=(bbox[0], bbox[1]),bottomRight=(bbox[2], bbox[3]),color=color,)        cv2.putText(frame, '77777', (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)        cv2.imshow(name, frame)
while True:

        imageQueueData = qRight.tryGet()

        detectQueueData = qDet.tryGet()
        if imageQueueData is not None:

            frame = imageQueueData.getCvFrame()
        if detectQueueData is not None:

            detections = detectQueueData.detections
        if frame is not None:

            displayFrame("rgb", frame)
        if cv2.waitKey(1) == ord("q"):

            break

cv2.destroyAllWindows()

The text format may be wrong. Please understand.

Thanks,

LI

    li_you_chen script.outputs['floodL'].link(manipOut .input)

    li_you_chen manip.out.link(manipOut.input)

    These are both outputting to the same queue.

    Hi, @Jackmarks

    I try to delete the manip.out.link(manipOut.input),Program works,but the frame size this very big,I think it is not the size we set(320x320),

    but,delete script.outputs['floodL'].link(manipOut .input),the error show

    [1944301061219A2E00] [1.1] [1.541] [Script(5)] [warning] IR drivers detected: [('LM3644', 2, 99)]

    [1944301061219A2E00] [1.1] [1.543] [Script(5)] [critical] KeyError: ('floodL',)

    At:

    <script>(31): <module>

    F: [global] [ 0] [ThreadN] dispatcherResponseServe:928 no request for this response: XLINK_READ_REL_RESP 1

    [1944301061219A2E00] [1.1] [1712407920.954] [host] [warning] Device crashed, but no crash dump could be extracted.

    Traceback (most recent call last):

    imageQueueData = qRight.tryGet()

    RuntimeError: Communication exception - possible device error/misconfiguration. Original message 'Couldn't read data from stream: 'flood-left' (X_LINK_ERROR)'

      li_you_chen [1944301061219A2E00] [1.1] [1.543] [Script(5)] [critical] KeyError: ('floodL',)

      This indicates a syntax error in the script node. I don't see the mistake in above code, I could have been introduces later. Please check.

      Thanks,
      Jaka