Hello everyone,
I am currently working on a project where I am using an NVIDIA Jetson Orin Nano with a Raspberry Pi 2 camera module connected via CSI interface. I have configured the camera to capture video at 1280x720 resolution at 60fps using OpenCV.
To verify that I am receiving frames at the correct rate, I am measuring the time interval between frames using cv2.VideoCapture.read()
and Python’s time
module. I expected to get a consistent 16ms interval between frames since the camera is set to 60fps. However, I am observing inconsistent intervals such as 25ms, 9ms, and other varying values.
Here is a simplified version of my code:
# MIT License
# Copyright (c) 2019-2022 JetsonHacks
# Using a CSI camera (such as the Raspberry Pi Version 2) connected to a
# NVIDIA Jetson Nano Developer Kit using OpenCV
# Drivers for the camera and OpenCV are included in the base image
import cv2
import time
"""
gstreamer_pipeline returns a GStreamer pipeline for capturing from the CSI camera
Flip the image by setting the flip_method (most common values: 0 and 2)
display_width and display_height determine the size of each camera pane in the window on the screen
Default 1920x1080 displayd in a 1/4 size window
"""
def gstreamer_pipeline(
sensor_id=0,
capture_width=1280,
capture_height=720,
display_width=960,
display_height=540,
framerate=60,
flip_method=0,
):
return (
"nvarguscamerasrc sensor-id=%d ! "
"video/x-raw(memory:NVMM), width=(int)%d, height=(int)%d, framerate=(fraction)%d/1 ! "
"nvvidconv flip-method=%d ! "
"video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
"videoconvert ! "
"video/x-raw, format=(string)BGR ! appsink"
% (
sensor_id,
capture_width,
capture_height,
framerate,
flip_method,
display_width,
display_height,
)
)
def show_camera():
window_title = "CSI Camera"
print(gstreamer_pipeline(flip_method=2))
video_capture = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)
prev_time = 0
if video_capture.isOpened():
try:
while True:
ret, frame = video_capture.read()
current_time = time.time() - prev_time
print(current_time)
prev_time = time.time()
cv2.imshow(window_title, frame)
finally:
video_capture.release()
cv2.destroyAllWindows()
else:
print("Error: Unable to open camera")
if __name__ == "__main__":
show_camera()
My questions are as follows:
1. Is it normal to experience such varying intervals even when the camera is set to 60fps?
2. Could this be due to hardware limitations or the way the Jetson Orin Nano handles CSI camera inputs?
3. Are there any known solutions or best practices to achieve a more consistent frame interval at 60fps?
4. Would using another method or API for capturing frames yield better results?
I would greatly appreciate any insights or suggestions that could help in diagnosing and resolving this issue.
Thank you for your assistance!