Jetson TX2 用opencv+python打开板载摄像头出错

代码如下:
import cv2

def open_cam_onboard(width, height):

On versions of L4T previous to L4T 28.1, flip-method=2

Use Jetson onboard camera

gst_str = (“nvarguscamerasrc ! video/x-raw(memory:NVMM),”
"width=(int)1920, height=(int)1080, format=(string)NV12, "
"framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, "
"width=(int){}, height=(int){}, format=(string)BGRx ! "
“videoconvert ! video/x-raw, format=(string)BGR !”
“appsink”).format(width, height)

return cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

cap = open_cam_onboard(1280, 720)

#cap = cv2.VideoCapture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)I420, framerate=(fraction)30/1 ! nvvidconv flip-method=0 ! video/x-raw, format=(string)$

#cap = cv2.VideoCapture(0)

#cap = cv2.VideoCapture(“nvcamerasrc”)

if cap is None:
print(“No Cam”)

while True:
_, frame = cap.read()

cv2.imshow("frame", frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
    break

cap.stop()
cv2.destroyAllWindows()

运行后报错提示如下:
GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 0
Output Stream W = 640 H = 480
seconds to Run = 0
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected…
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.

(python3:13943): GStreamer-CRITICAL **: gst_element_get_static_pad: assertion ‘GST_IS_ELEMENT (element)’ failed

(python3:13943): GStreamer-CRITICAL **: gst_pad_get_current_caps: assertion ‘GST_IS_PAD (pad)’ failed

(python3:13943): GStreamer-CRITICAL **: gst_caps_get_structure: assertion ‘GST_IS_CAPS (caps)’ failed

(python3:13943): GStreamer-CRITICAL **: gst_structure_get_int: assertion ‘structure != NULL’ failed

(python3:13943): GStreamer-CRITICAL **: gst_structure_get_int: assertion ‘structure != NULL’ failed

(python3:13943): GStreamer-CRITICAL **: gst_structure_get_fraction: assertion ‘structure != NULL’ failed
GST_ARGUS: Cleaning up
CONSUMER: Done Success
GST_ARGUS: Done Success
GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 0
Output Stream W = 640 H = 480
seconds to Run = 0
段错误 (核心已转储)

Hi,
r28.1 is old release. re you able to upgrade to r32 release and try? The latest release is r32.5.1(Jetpack4.5.1).

There is a sample for your reference:
OpenCV Video Capture with GStreamer doesn't work on ROS-melodic - #3 by DaneLLL