I used OpenCV4.0 with gstreamer built. But my CSI camera cannot be read by OpenCV.
I installed L4T R31 with Jetack4.1, and replaced OpenCV.
I’ve tested that nvgstcapture-1.0 is working with my camera.
My python code is:
Can anyone provide an example to read CSI camera
gst_str = ('nvarguscamerasrc !'
'video/x-raw(memory:NVMM), '
'width=(int)1280, height=(int)720, '
'format=(string)NV12, framerate=30/1 ! '
'nvvidconv ! '
'video/x-raw, format=(string)BGRx ! '
'videoconvert ! '
'video/x-raw, format=(string)RGB ! appsink')
cap = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)
if not cap.isOpened():
print('Failed to open camera!')
sys.exit()
while(True):
_, img = cap.read() # grab the next image frame from camera
cv2.imshow("cam", img)
key = cv2.waitKey(10)
Output is:
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 3840 x 2160 FR = 59.999999 fps; Analog Gain range min 1.000000, max 44.400002; Exposure Range min 44000, max 666637000;
GST_ARGUS: 1920 x 1080 FR = 59.999999 fps; Analog Gain range min 1.000000, max 177.000000; Exposure Range min 58000, max 184611000;
GST_ARGUS: 3840 x 2160 FR = 29.999999 fps; Analog Gain range min 1.000000, max 30.000000; Exposure Range min 57000, max 20480000;
GST_ARGUS: 1920 x 1080 FR = 59.999999 fps; Analog Gain range min 1.000000, max 177.000000; Exposure Range min 56000, max 666479000;
GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 3
Output Stream W = 1920 H = 1080
seconds to Run = 0
Frame Rate = 59.999999
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
(python:9915): GStreamer-CRITICAL **: 17:07:59.361: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed
Failed to open camera!