Hello everybody!

I am using two IMX378 cameras connected to an OAK-FFC 4P module. I need to improve the delay between image acquisition and display on screen, which is more than one second. At the same time, I have a very low fluency in the video, this is because it does not work at the fps that I indicate. Below is an image that shows the delay mentioned and the fps.

I don't know if it is a hardware limitation and therefore a delay that I have to deal with, or if there is any possible way or technique to improve this code.

If I do not use "cam1.setIspScale(1,2)" the delay is ~4 seconds.

import cv2
import depthai as dai
import time

def getFrame(queue):
    frame = queue.get()
    return frame.getCvFrame()

if __name__ == '__main__':

    fps = 10
    frame_count = 0
    
    # Define a pipeline
    pipeline = dai.Pipeline()
    device = dai.Device()

    # DEFINE SOURCES AND OUTPUTS
    cam1 = pipeline.create(dai.node.ColorCamera)
    cam2 = pipeline.create(dai.node.ColorCamera)
    cam1.setBoardSocket(dai.CameraBoardSocket.CAM_A)  # 4-lane MIPI  IMX378
    cam2.setBoardSocket(dai.CameraBoardSocket.CAM_D)  # 4-lane MIPI  IMX378
    cam1.setResolution(dai.ColorCameraProperties.SensorResolution.THE_12_MP)
    cam2.setResolution(dai.ColorCameraProperties.SensorResolution.THE_12_MP)
    cam1.setIspScale(1,2)
    cam2.setIspScale(1,2)
    cam1.setFps(fps)
    cam2.setFps(fps)
    # Set output Xlink 
    outcam1 = pipeline.create(dai.node.XLinkOut)
    outcam2 = pipeline.create(dai.node.XLinkOut)
    outcam1.setStreamName("cam1")
    outcam2.setStreamName("cam2")
    # LINKING
    cam1.isp.link(outcam1.input)
    cam2.isp.link(outcam2.input)

    outcam1.input.setBlocking(False)
    outcam2.input.setBlocking(False)
    outcam1.input.setQueueSize(1)
    outcam2.input.setQueueSize(1)

    with device:
        device.startPipeline(pipeline)
        cam1 = device.getOutputQueue(name="cam1", maxSize=1, blocking=False)
        cam2 = device.getOutputQueue(name="cam2", maxSize=1, blocking=False)
        n=0

        while True:
            frame_count += 1
            n+=1
            
            elapsed_time = time.time() - start_time
            if elapsed_time > 1.0:
                fps = frame_count / elapsed_time
                print(f"FPS: {fps:.2f}\n")
                frame_count = 0
                start_time = time.time()

            start_adq = time.time()  # Inicia el temporizador

            Frame1 = getFrame(cam1)
            #Frame2 = getFrame(cam2)

            end_adq = time.time()  # Detiene el temporizador
            tiempo_adquisicion = end_adq - start_adq
            print(n,f"- acquisition time: {tiempo_adquisicion} seconds")

            # Check for keyboard input
            key = cv2.waitKey(1) & 0xFF

            # Display the current state in the window
            cv2.imshow("Frame1", Frame1)
            #cv2.imshow("Frame2", Frame2)

            if key == ord('q'):
                break

Thank you very much

    Hi MartnTous
    A and D sockets on the FFC-4P are not synced by default.
    You should be able to enable hardware link between the two by setting:

    cam_A.initialControl.setFrameSyncMode(dai.CameraControl.FrameSyncMode.OUTPUT)
    cam_D.initialControl.setFrameSyncMode(dai.CameraControl.FrameSyncMode.INPUT)

    Let me know if this works.

    Thanks,
    Jaka

    Hi @jakaskerl! Thanks for your response.

    What is the purpose of synchronizing both cameras? I did it but I don't notice an improvement in acquisition latency.

      Hi MartnTous
      Not sure how, but I read "delay between the cameras..".

      Regarding the acquisition->display latency, this is a hardware limitation. You can run the pipeline in TRACE mode (DEPTHAI_LEVEL=TRACE python3 ...) to see how long each frame (acquisition, processing, ..) takes. Expect higher latency with 12MP since that is a lot of info to handle on a single board. Using ISP downscaling helps since the ISP is performant (600MP/s), other HW, not so much.

      https://docs.luxonis.com/projects/api/en/latest/components/nodes/camera/#limitations

      Thanks,
      Jaka

      Hi @jakaskerl

      I assumed it had to do with hardware limitations, but after running in debug mode, I noticed that the memory and cpu usage is low, which I found strange (this can be seen in the image I attached above).

      As for the ISP processing capability being 600 MP/s I also find it odd that this is a limiter, since I am working with ISP downscaling. Even if I wasn't using downscaling and working with the 12 MP, I'm working at 5fps, with two cameras at a time, so 12x5x2=120 MP/s, which is considerably less than the 600 MP/s capacity.

      Maybe it's another limiting hardware component? Or does it have to do with my acquisition script (maybe there is a way to make it more efficient)?

      Hi @MartnTous
      Yes, the isp is not the issue here. It's other hardware. Trace mode should show how long each operation takes.

      Thanks,
      Jaka