Ability to capture 30 fps

Hey all
my current set up is the following:

Jetson AGX orin 32Gb Devkit
Zed2i

everything is stock and I haven’t added any SSDs to the orin.

the following is my code

import pyzed.sl as sl
import cv2
import os
import concurrent.futures
import numpy as np
import pexpect
import time
import logging

def setup_logging():
    # Create a logger
    logger = logging.getLogger("zed_cameras")
    logger.setLevel(logging.DEBUG)

    # Create a file handler to save logs to a text file
    log_file = "zed_cameras_log.txt"
    file_handler = logging.FileHandler(log_file)
    file_handler.setLevel(logging.DEBUG)

    # Create a formatter to define log message format
    formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
    file_handler.setFormatter(formatter)

    # Add the file handler to the logger
    logger.addHandler(file_handler)

    return logger

def capture_and_send_images(camera_id, serial_number):
    save_directory = "captured-image"
    frame_count = 0

    init_params = sl.InitParameters()
    init_params.camera_resolution = sl.RESOLUTION.HD720  # Use HD720 video mode
    init_params.camera_fps = 30  # Set FPS at 60
    init_params.set_from_serial_number(serial_number)

    logger = logging.getLogger(f"zed_cameras.camera{camera_id}")

    while True:
        zed = sl.Camera()
        err = zed.open(init_params)
        if err == sl.ERROR_CODE.SUCCESS:
            logger.info(f"Camera {camera_id} (Serial Number: {serial_number}) opened successfully.")
            break
        else:
            logger.warning(f"Failed to open Camera {camera_id} (Serial Number: {serial_number}). Retrying in 2 seconds...")
            zed.close()
            time.sleep(2)

    runtime_parameters = sl.RuntimeParameters()
    runtime_parameters.sensing_mode = sl.SENSING_MODE.STANDARD

    while frame_count < 60:
        if zed.grab(runtime_parameters) == sl.ERROR_CODE.SUCCESS:
            right_image = sl.Mat()
            zed.retrieve_image(right_image, sl.VIEW.RIGHT)
            depth_map = sl.Mat()
            zed.retrieve_measure(depth_map, sl.MEASURE.DEPTH)
            depth_array = depth_map.get_data()

            # Convert right image to numpy array
            right_image_array = right_image.get_data()

            # Save the images and depth maps
            depth_filename = f"dm{camera_id}_{frame_count}.txt"
            depth_filepath = os.path.join(save_directory, depth_filename)
            np.savetxt(depth_filepath, depth_array, delimiter=',')

            right_image_filename = f"rm{camera_id}_{frame_count}.png"
            right_image_filepath = os.path.join(save_directory, right_image_filename)
            cv2.imwrite(right_image_filepath, right_image_array)

           

            # Increment the frame count
            frame_count += 1

    zed.close()
    logger.info(f"Capture and transfer finished for Camera {camera_id} (Serial Number: {serial_number})")
def main():
    # Setup logging
    logger = setup_logging()

    # Creating initial parameters
    init = sl.InitParameters()
    init.camera_resolution = sl.RESOLUTION.HD720
    init.camera_fps = 30

    cameras = [
        (1, 16007846),
        (2, 18990712)
    ]

    with concurrent.futures.ProcessPoolExecutor() as executor:
        futures = [executor.submit(capture_and_send_images, camera_id, serial_number) for camera_id, serial_number in cameras]
        concurrent.futures.wait(futures)

    print("All captures and transfers finished.")

if __name__ == "__main__":
    main()

when clearing the directory so that it does not lag when replacing the file I was only able to hit 2 FPS or 60 images over 30.48 seconds. would it be possible to save at a faster rate?

Hi,
Saving images and moreover depth data is hard to achieve in real time. consider to first save a SVO file and then export it as files in an offline process.

ps: depth is computed related to the left image. You can retrieve the depth for the Right Image but it requires more computation.

i’d like to get around 30 frames saved per second on my device, i installed a 970 evo plus ssd hoping it would net me better results

You will struggle to save imagery at the rate is is produced using the eMMC chip that the jetson uses by default, as the write-speed on the disk is not consistently fast enough.

I recommend switching to an SSD and doing regular disk benchmarks to track it’s performance. In our application we find that most consumer-grade SSDs degrade to the point where we will suffer write-delays within a few months of fulltime usage, at which point they will need replacement.

1 Like

when running it with an ssd i have noticed the rate jump from 1.9~2 fps up to 4.77 (this is with perfect conditions and without any pre-existing images)