As there’re no requirements for saving the timestamps and the information of IMU, I did not record the images as the ‘*.svo’ format and directly use ZED2 as a webcam. I am using ZED2 as a webcam to save images.
The platform I am using is Jetson Nano. I followed the tutorials for catching images and saving the matrixes as the format of ‘*.npy’. I set fps as 30 but I only got the fps as around 4 frame/s.
My codes for recording and saving images as the ‘*.npy’ formats are in the ends.
My problem is, how can I record and save iamges or videos with a FPS around 20 f/s to 30 f/s and with a small saving space.
Thanks in advance. Looking forward to hearing from you.
Best regads,
import pyzed.sl as sl
import numpy as np
import os
if not os.path.exists(path_r):
os.mkdir(path_r)
print("Right folder doesn't exise, creating ...")
else:
print("Directly recording ...")
# 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
# Open the camera
err = zed.open(init_params)
if err != sl.ERROR_CODE.SUCCESS:
exit(1)
i = 0
image = sl.Mat()
image_r = 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:
# A new image is available if grab() returns SUCCESS
zed.retrieve_image(image, sl.VIEW.LEFT)
zed.retrieve_image(image_r, sl.VIEW.RIGHT)
image_left = image.get_data()
image_right = image_r.get_data()
path_l_save = path_l + 'left_' + str(i) + '.npy'
path_r_save = path_l + 'right_' + str(i) + '.npy'
np.save(path_l_save, image_left)
np.save(path_r_save, image_right)
# print('Successfully save images.')
i = i + 1
zed.close()
The format of svo costs to much space for storing. Are there any possibilities that I directly use ZED2 as a webcam and have a higher fps as 20 frames/s or even 30 frames/s?
The storage of svo format is too large, how can I directly record as a video with the format avi? I also need to make sure that the fps is as higher as it can.
Do you mean following the code for recording svo? How can I replace the ‘SVO input’ with the ‘live input’? Is there the specific code in the stereolab library to replace sl.SVO_COMPRESSION_MODE.H264? Thanks.
@Qingwu I’ve seen your code, that’s why I suggested you look at the SVO exporting example.
In your code you are saving RAW data, that’s a heavy operation that requires a lot of available disk space.
@Qingwu the zed-examples repository contains many examples and tutorials describing how to use the camera.
You can start from the tutorial 1 that illustrates how to open the camera.
The tutorial 2 explains how to retrieve the images.
The zed-opencv repository illustrates an easy way to display the retrieved images by using OpenCV.
Finally you can put everything together by modifying the sv-export tutorial in order to use live images as input instead of an SVO file.
@Myzhar I do tried to follow tutorial 1 and 2 to generate live images to save into a video. Then it came back to my previous question, I used opencv to read the sl.mat() and save it into images, fps is very low (about 3.7 frames/s). How can I have a higher fps? Thanks.