Hi,
I bought NVIDIA Jetson Xavier and 4 MIPI cameras connected through ECON- Module. I wanted to capture single-shot images from all cameras in less than a second. I can access all the cameras synchronously at a frame rate of 30FPS and asynchronously at a frame rate of 120FPS. I understood that it is possible to acquire images through Gstreamer,v4l2, and Libargus. I found it difficult to understand the Tegra multimedia samples. So, I implemented the image capturing using Gstreamer which runs at the maximum frame rate and the code snippet is given below. It takes around 5s to capture the images from all the cameras (excluding the undistort images). I have three questions,
-
Is it possible to speed up the image capturing process using GStreamer?
-
Is it possible to access all the cameras in a single pipeline and capture single-shot images using GStreamer in less than a second?
-
If the above two is impossible and if it can be done only through Argus. Is it possible to provide sample code for multi-camera_jpeg_capture similar to 09_camera_jpeg_capture from tegra_multimedia_api as 13_multi_camera does not provide the option to store in the drive?
import numpy as np
import cv2
import sys
import os
import yaml
import time
def gstreamer_pipeline (capture_width=1920, capture_height=1080, display_width=1920, display_height=1080, framerate=120, flip_method=0) :
return ('nvarguscamerasrc sensor-id= 0 ! '
'video/x-raw(memory:NVMM),'
'width=(int)%d, height=(int)%d, '
'format=(string)NV12, 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' % (capture_width,capture_height,framerate,flip_method,display_width,display_height))
def gstreamer_pipeline1 (capture_width=1920, capture_height=1080, display_width=1920, display_height=1080, framerate=120, flip_method=0) :
return ('nvarguscamerasrc sensor-id= 1 ! '
'video/x-raw(memory:NVMM),'
'width=(int)%d, height=(int)%d, '
'format=(string)NV12, 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' % (capture_width,capture_height,framerate,flip_method,display_width,display_height))
def gstreamer_pipeline2 (capture_width=1920, capture_height=1080, display_width=1920, display_height=1080, framerate=120, flip_method=0) :
return ('nvarguscamerasrc sensor-id= 2 ! '
'video/x-raw(memory:NVMM),'
'width=(int)%d, height=(int)%d, '
'format=(string)NV12, 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' % (capture_width,capture_height,framerate,flip_method,display_width,display_height))
def gstreamer_pipeline3 (capture_width=1920, capture_height=1080, display_width=1920, display_height=1080, framerate=120, flip_method=0) :
return ('nvarguscamerasrc sensor-id= 3 ! '
'video/x-raw(memory:NVMM),'
'width=(int)%d, height=(int)%d, '
'format=(string)NV12, 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' % (capture_width,capture_height,framerate,flip_method,display_width,display_height))
def Img_Capture(K,D,DIM):
i = 0
cap = cv2.VideoCapture(gstreamer_pipeline(), cv2.CAP_GSTREAMER)
ret_val, img = cap.read()
map1, map2 = cv2.fisheye.initUndistortRectifyMap(np.array(K), np.array(D), np.eye(3), np.array(K), DIM, cv2.CV_16SC2)
undistorted_img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
if ret_val == 1:
img_dir = '/home/fcr/Python_Programs/Images/Stitch/im' + str(i) + '.bmp'
cv2.imwrite(img_dir,undistorted_img)
i = i+1
cap.release()
cap = cv2.VideoCapture(gstreamer_pipeline1(), cv2.CAP_GSTREAMER)
ret_val, img = cap.read()
map1, map2 = cv2.fisheye.initUndistortRectifyMap(np.array(K), np.array(D), np.eye(3), np.array(K), DIM, cv2.CV_16SC2)
undistorted_img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
if ret_val == 1:
img_dir = '/home/fcr/Python_Programs/Images/Stitch/im' + str(i) + '.bmp'
cv2.imwrite(img_dir,undistorted_img)
i = i+1
cap.release()
cap = cv2.VideoCapture(gstreamer_pipeline2(), cv2.CAP_GSTREAMER)
ret_val, img = cap.read()
map1, map2 = cv2.fisheye.initUndistortRectifyMap(np.array(K), np.array(D), np.eye(3), np.array(K), DIM, cv2.CV_16SC2)
undistorted_img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
if ret_val == 1:
img_dir = '/home/fcr/Python_Programs/Images/Stitch/im' + str(i) + '.bmp'
cv2.imwrite(img_dir,undistorted_img)
i = i+1
cap.release()
cap = cv2.VideoCapture(gstreamer_pipeline3(), cv2.CAP_GSTREAMER)
ret_val, img = cap.read()
map1, map2 = cv2.fisheye.initUndistortRectifyMap(np.array(K), np.array(D), np.eye(3), np.array(K), DIM, cv2.CV_16SC2)
undistorted_img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
if ret_val == 1:
img_dir = '/home/fcr/Python_Programs/Images/Stitch/im' + str(i) + '.bmp'
cv2.imwrite(img_dir,undistorted_img)
i = i+1
cap.release()
if __name__ == '__main__':
start = time.time()
with open("/home/fcr/Python_Programs/Fish_eye_Calib.yaml", 'r') as stream:
data = yaml.load(stream)
K = data["K"]
D = data["D"]
DIM = data["DIM"]
Img_Capture(K,D,DIM)
end = time.time()
print("Time Taken: ",end-start)
Output:
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1920 x 1080 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1920 x 1080 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 2
Output Stream W = 1920 H = 1080
seconds to Run = 0
Frame Rate = 120.000005
GST_ARGUS: PowerService: requested_clock_Hz=108864000
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
GST_ARGUS: Cleaning up
CONSUMER: Done Success
GST_ARGUS: Done Success
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1920 x 1080 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1920 x 1080 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: Running with following settings:
Camera index = 1
Camera mode = 2
Output Stream W = 1920 H = 1080
seconds to Run = 0
Frame Rate = 120.000005
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
GST_ARGUS: Cleaning up
CONSUMER: Done Success
GST_ARGUS: Done Success
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1920 x 1080 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1920 x 1080 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: Running with following settings:
Camera index = 2
Camera mode = 2
Output Stream W = 1920 H = 1080
seconds to Run = 0
Frame Rate = 120.000005
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
GST_ARGUS: Cleaning up
CONSUMER: Done Success
GST_ARGUS: Done Success
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1920 x 1080 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1920 x 1080 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 31.622776; Exposure Range min 450000, max 400000000;
GST_ARGUS: Running with following settings:
Camera index = 3
Camera mode = 2
Output Stream W = 1920 H = 1080
seconds to Run = 0
Frame Rate = 120.000005
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
GST_ARGUS: Cleaning up
CONSUMER: Done Success
GST_ARGUS: Done Success
('Time Taken: ', 5.643635034561157)
GST_ARGUS:
PowerServiceHwVic::cleanupResources