luxonis / depthai-python

DepthAI Python Library
MIT License
349 stars 190 forks source link

MonoCamera's FPS is different on Linux and Windows #519

Open richard-xx opened 2 years ago

richard-xx commented 2 years ago

With the same device and the same type-c cable, running depth camera with the following code gives almost 120 FPS on ubuntu but only about 60 FPS on Windows 10.

Can you provide some advice? Under what conditions does OAK-D's depth camera get 120 FPS on Windows platform?

#!/usr/bin/env python3

import cv2
import depthai as dai
import numpy as np

from depthai_sdk import FPSHandler, getDeviceInfo

# Create pipeline
pipeline = dai.Pipeline()

monoLeft = pipeline.create(dai.node.MonoCamera)
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT)
monoLeft.setFps(120)

monoRight = pipeline.create(dai.node.MonoCamera)
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
monoRight.setBoardSocket(dai.CameraBoardSocket.RIGHT)
monoRight.setFps(120)

# Create a node that will produce the depth map (using disparity output as it's easier to visualize depth this way)
depth = pipeline.create(dai.node.StereoDepth)
# Better handling for occlusions:
depth.setLeftRightCheck(False)
# Closer-in minimum depth, disparity range is doubled:
depth.setExtendedDisparity(False)
# Better accuracy for longer distance, fractional disparity 32-levels:
depth.setSubpixel(False)

xout = pipeline.create(dai.node.XLinkOut)
xout.setStreamName("disparity")

monoLeft.out.link(depth.left)
monoRight.out.link(depth.right)
depth.disparity.link(xout.input)

# Connect to device and start pipeline
with dai.Device(pipeline, getDeviceInfo()) as device:
    # Print Myriad X Id (MxID), USB speed, and available cameras on the device
    print('MxId:',device.getDeviceInfo().getMxId())
    print('USB speed:',device.getUsbSpeed())
    print('Connected cameras:',device.getConnectedCameras())

    q = device.getOutputQueue(name="disparity", maxSize=4, blocking=False)
    # q = device.getOutputQueue(name="disparity")

    fps_handler = FPSHandler()
    frame = None

    while True:
        inDisparity = q.get()  # blocking call, will wait until a new data has arrived
        fps_handler.tick("Frame")
        # fps_handler.printStatus()

        frame = inDisparity.getFrame()
        # Normalization for better visualization
        frame = (frame * (255 / depth.initialConfig.getMaxDisparity())).astype(np.uint8)

        fps_handler.drawFps(frame,"Frame")
        cv2.imshow("disparity", frame)

        # Available color maps: https://docs.opencv.org/3.4/d3/d50/group__imgproc__colormap.html
        frame = cv2.applyColorMap(frame, cv2.COLORMAP_JET)

        fps_handler.drawFps(frame,"Frame")
        cv2.imshow("disparity_color", frame)

        if cv2.waitKey(1) == ord('q'):
            break
Erol444 commented 2 years ago

Hello @richard-xx , from quick calculation this looks like USB2 speed limit (480mbps) - do you get USB speed: SUPER log on both Windows and Ubuntu? Thanks, Erik

richard-xx commented 2 years ago

I get USB speed: SUPER log on both Windows and Ubuntu

themarpe commented 2 years ago

@Erol444 are you able to reproduce?

@richard-xx what are the specifications of your host machine? Which CPU in particular? (and amount of total and free memory preferably) Can you try commenting out the following and retest:

    while True:
        inDisparity = q.get()  # blocking call, will wait until a new data has arrived
        fps_handler.tick("Frame")
        fps_handler.printStatus()

        # frame = inDisparity.getFrame()
        # # Normalization for better visualization
        # frame = (frame * (255 / depth.initialConfig.getMaxDisparity())).astype(np.uint8)

        # fps_handler.drawFps(frame,"Frame")
        # cv2.imshow("disparity", frame)

        # # Available color maps: https://docs.opencv.org/3.4/d3/d50/group__imgproc__colormap.html
        # frame = cv2.applyColorMap(frame, cv2.COLORMAP_JET)

        # fps_handler.drawFps(frame,"Frame")
        # cv2.imshow("disparity_color", frame)

        if cv2.waitKey(1) == ord('q'):
            break
richard-xx commented 2 years ago

Ubuntu: 22.04 CPU: Intel(R) Xeon(R) CPU E5-2670 v3 @ 2.30GHz MemTotal: 65844964 kB MemFree: 49881412 kB MemAvailable: 56756416 kB

Windows 10: 19042.1526 CPU: AMD Ryzen 5 3600 6-Core Processor @ 3.59 GHz RAM: 32.0 GB

Available devices:
[0] 14442C1051B83BD400 [X_LINK_UNBOOTED]
MxId: 14442C1051B83BD400
[14442C1051B83BD400] [47.728] [system] [warning] MonoCamera OV9282: capping FPS for selected resolution to 120
USB speed: UsbSpeed.SUPER
Connected cameras: [<CameraBoardSocket.RGB: 0>, <CameraBoardSocket.LEFT: 1>, <CameraBoardSocket.RIGHT: 2>]
=== TOTAL FPS ===
[Frame]: 0.0
=== TOTAL FPS ===
[Frame]: 66.7
=== TOTAL FPS ===
[Frame]: 133.3
=== TOTAL FPS ===
[Frame]: 63.8
=== TOTAL FPS ===
[Frame]: 85.1
=== TOTAL FPS ===
[Frame]: 64.1
=== TOTAL FPS ===
[Frame]: 76.9
=== TOTAL FPS ===
[Frame]: 74.5
=== TOTAL FPS ===
[Frame]: 73.4
=== TOTAL FPS ===
[Frame]: 72.0
=== TOTAL FPS ===
[Frame]: 80.0
=== TOTAL FPS ===
[Frame]: 78.6
=== TOTAL FPS ===
[Frame]: 76.9
=== TOTAL FPS ===
[Frame]: 75.6
=== TOTAL FPS ===
[Frame]: 74.9
=== TOTAL FPS ===
[Frame]: 73.9
=== TOTAL FPS ===
[Frame]: 78.8
=== TOTAL FPS ===
[Frame]: 77.6
=== TOTAL FPS ===
[Frame]: 76.9
=== TOTAL FPS ===
[Frame]: 76.0
=== TOTAL FPS ===
[Frame]: 75.5
=== TOTAL FPS ===
[Frame]: 74.7
=== TOTAL FPS ===
[Frame]: 74.1
=== TOTAL FPS ===
[Frame]: 73.7
=== TOTAL FPS ===
[Frame]: 76.9
=== TOTAL FPS ===
[Frame]: 76.2
=== TOTAL FPS ===
[Frame]: 75.6
...
Erol444 commented 2 years ago

@themarpe I wasn't able to reproduce the issue, I usually get about 100-120 FPS on both Ubuntu and Windows, but it's changing quate a bit, I assume due to FPS calculation logic.

themarpe commented 2 years ago

@richard-xx Only thing that come to think of is either a consumed bandwidth by some other USB devices? Does same happen on some other root USB port? Eg. make sure you are not connected to a USB hub with ethernet port or video output running alongside, etc...

Otherwise you may try xlink_device_search_improvements, but currently the prebuilt wheels aren't available. You'd have to compile from source