我正在尝试读取 Jetson Xavier(ubuntu 18)上的相机图像。我面临一个问题。当我运行以下代码时,它会发出警告并给出黑色(完整)图像。
[警告:0] 全局 /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (933) 打开 OpenCV | GStreamer 警告:无法查询视频位置:状态=0,值=-1,持续时间=-1
cam=cv2.VideoCapture(0)
if cam.isOpened():
grab,img = cam.read()
if grab is True:
cv2.imshow('sample image',img)
else:
print(f"Image not found")
else:
print("Camera not openedd")
cv2.waitKey(0) # waits until a key is pressed
cv2.destroyAllWindows() # destroys the window showing image
如果我使用“dev/video0”来读取图像,即
cam=cv2.VideoCapture('dev/video0')
我收到未打开相机的警告和自定义错误消息
[警告:0] 全局 /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (711) 打开 OpenCV | GStreamer 警告:打开 bin 时出错:没有元素“dev” [WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer 警告:GStreamer:管道尚未创建相机未打开
然后我创建了 gstream 字符串并将其传递给视频捕获,如下所示。字符串如下
gstr = 'varguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)60/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)1280, height=(int)720, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink'
cap = cv2.VideoCapture(gstr, cv2.CAP_GSTREAMER)
我收到以下错误
Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, execute:645 No cameras available
(python3:15402): GStreamer-CRITICAL **: 19:08:54.835: gst_mini_object_set_qdata: assertion 'object != NULL' failed
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (933) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
Traceback (most recent call last):
我是jetson的新手,请指导我。谢谢