FPS varies from mentioned initial parameters

Hi,
I’m using python to work use the zed sdk, I have mentioned the frame rate and the resolution in the initial parameters the camera gets the frames at lower fps.

import pyzed.sl as sl
import cv2
import numpy as np
import math


def main():
    # Create a Camera object
    zed = sl.Camera()

    # Create a InitParameters object and set configuration parameters
    init_params = sl.InitParameters()
    init_params.camera_resolution = sl.RESOLUTION.SVGA  # Use HD1080 video mode
    init_params.camera_fps = 120  # Set fps at 30
    init_params.sdk_verbose = True  # Enable the verbose mode
    init_params.depth_mode = (
        sl.DEPTH_MODE.QUALITY
    )  # Set the depth mode to performance (fastest)
    init_params.coordinate_units = sl.UNIT.CENTIMETER  # Use meter units (for depth measurements)

    # Open the camera
    err = zed.open(init_params)
    if err != sl.ERROR_CODE.SUCCESS:
        exit(1)

    # Capture 50 frames and stop
    i = 0
    image = sl.Mat()
    depth = sl.Mat()
    point_cloud = sl.Mat()

    runtime_parameters = sl.RuntimeParameters()
    while True:
        # Grab an image, a RuntimeParameters object must be given to grab()
        if zed.grab(runtime_parameters) == sl.ERROR_CODE.SUCCESS:
            print("FPS",zed.get_current_fps())
            # A new image is available if grab() returns SUCCESS
            zed.retrieve_image(image, sl.VIEW.LEFT)
            zed.retrieve_measure(depth, sl.MEASURE.DEPTH)
            color_image = image.get_data()
            depth_image = depth.get_data()
            depth_colormap = cv2.applyColorMap(
                cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET
            )

            cv2.namedWindow("ZED X ", cv2.WINDOW_AUTOSIZE)
            color_image = cv2.circle(color_image, (900,500), radius=2 , color=(0, 0, 255), thickness=-1)
            cv2.imshow("ZED X ", color_image)

            # Get the 3D point cloud values for pixel (i, j)

            cv2.waitKey(1)
            if cv2.waitKey(10) & 0xFF == ord("q"): #113
                zed.retrieve_measure(point_cloud, sl.MEASURE.XYZRGBA)
                #point_cloud.write("test.pcd")
                err, point_cloud_value = point_cloud.get_value(900, 500)

                x, y, z, color = point_cloud_value
                distance = math.sqrt(
                    x *x + y * y + z * z
                )
                print(f"Distance to Camera at : {distance}")
                
                break

    # Close the camera
    zed.close()


if __name__ == "__main__":
    main()

If I change the depth mode to performance, the fps goes upto 20.

Hi, the FPS you set as init parameter is the FPS of the video capture of the camera.
the value you get by calling get_current_fps is your global application FPS, this may be lower than the one you set depending on your hardware compute power and your overall application load.

How to get the correct FPS of the video stream?
We are using zed box.

What do you mean by “video stream” ?
The video itself will reach the FPS you asked for in the initParameters. However, the real fps of your application will be defined by how many time you can run grab() per second. This can be retrieved with get_current_fps

You’re saying that the camera can capture the frames at the mentioned parameters but in order to use it, it depends on the grab() which ultimately depends on the processing capability.
right?
If so, then what is the nominal speed at which the frames can be grabbed and processed by grab()
Is there any way to improve it?
We are using zed x with zed box

What you say is right.

What do you mean by “nominal speed” ? If will depends on what you do with the camera. If you just use PERFORMANCE depth, you can easily reach a high FPS, which you cannot with a heavier depth like NEURAL

By nominal I mean the normal rate at which frames can be grabbed using the grab() from the zed x camera with zed box at various depth modes.

Even in the performance mode, for Video mode: HD1080@30, I was getting around 20 fps using get_current_fps.

Is there any way to improve it?

This is really weird. Can show / send the code you are using ?

Sure,

import pyzed.sl as sl
import cv2
import numpy as np
import math


def main():
    # Create a Camera object
    zed = sl.Camera()

    # Create a InitParameters object and set configuration parameters
    init_params = sl.InitParameters()
    init_params.camera_resolution = sl.RESOLUTION.HD1080  # Use HD1080 video mode
    init_params.camera_fps = 30  # Set fps at 30
    init_params.sdk_verbose = True  # Enable the verbose mode
    init_params.depth_mode = (
        sl.DEPTH_MODE.PERFORMANCE
    )  # Set the depth mode to performance (fastest)
    init_params.coordinate_units = sl.UNIT.CENTIMETER  # Use meter units (for depth measurements)

    # Open the camera
    err = zed.open(init_params)
    if err != sl.ERROR_CODE.SUCCESS:
        exit(1)

    image = sl.Mat()
    depth = sl.Mat()
    point_cloud = sl.Mat()

    runtime_parameters = sl.RuntimeParameters()
    while True:
        # Grab an image, a RuntimeParameters object must be given to grab()
        if zed.grab(runtime_parameters) == sl.ERROR_CODE.SUCCESS:
            print("FPS",zed.get_current_fps())
            # A new image is available if grab() returns SUCCESS
            zed.retrieve_image(image, sl.VIEW.LEFT)
            zed.retrieve_measure(depth, sl.MEASURE.DEPTH)
            color_image = image.get_data()
            depth_image = depth.get_data()

    # Close the camera
    zed.close()


if __name__ == "__main__":
    main()

Hi @Gopi-htic ,

Your code seems pretty straightforward to me, I don’t see anything that could justify the performance loss. What power mode are you using on the ZED Box? Low performance could come from the 15W power mode.

Hi @JPlou,
I am using 25W power mode.

I could not reproduce your issue using your code, I get a steady 30 fps. Even when trying 1200p60fps, I’m at ~45 fps.

Can you share the report file of ZED Diagnostic?

ZED_Diagnostic_Results.json (5.3 KB)

What fps do you get in when using NONE depth mode in 1080@30 and 1200p@60 fps?

Also, what camera and depth frequency do you get in these resolutions in ZED_DepthViewer? (You can see it in the bottom left of the window)

When using NONE depth mode, I’m getting the mentioned frame rates.
for HD1080@30, I’m getting 30fps and for the HD1200@60, I’m getting 60fps.

In ZED_DepthViewer, at 1200@60, I’m getting around 14Hz for depth.
At 1080@30, the depth is around 15Hz.

There seems to be something quite weird with your hardware.
Can you run

sudo apt install --reinstall nvidia-jetpack

?

Reinstalled nvidia jetack,
still the feed is at 20 fps

@Gopi-htic
There is probably something wrong with your hardware. I encourage you to contact support@stereolabs.com with your order number and description of the issue to initiate a warranty claim.