运行 OpenCV 在 Ubuntu 上时出现 GStreamer 警告
GStreamer warning when running OpenCV on Ubuntu
我正在尝试在我的 raspberry pi(Ubuntu 系统)上获取脚本 运行ning。现在,我只是在复习 opencv 的基础知识,因为我已经有一段时间没有使用它了。所以我直接从 OpenCV 网站复制粘贴了这段代码,然后 运行 它。
import numpy as np
import cv2 as cv
cap = cv.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
exit()
while True:
# Capture frame-by-frame
ret, frame = cap.read()
# if frame is read correctly ret is True
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
# Our operations on the frame come here
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
# Display the resulting frame
cv.imshow('frame', gray)
if cv.waitKey(1) == ord('q'):
break
# When everything done, release the capture
cap.release()
cv.destroyAllWindows()
只是,运行它给了我一个纯灰色 window 作为弹出窗口并抛出这些错误:
[ WARN:0] global /usr/local/src/opencv-4.4.0/modules/videoio/src/cap_gstreamer.cpp (1761) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Internal data stream error.
[ WARN:0] global /usr/local/src/opencv-4.4.0/modules/videoio/src/cap_gstreamer.cpp (888) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global /usr/local/src/opencv-4.4.0/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
代码仍然 运行,因为我可以通过按 'q' 关闭 window。但是视频流部分出现了严重错误。我什至不知道什么是 GStreamer,更不知道什么是 GStreamer 管道。我不知道如何解决这个问题,也没有在网上找到任何有效的方法。
我的代码在 jetson nano
上运行 运行
def __gstreamer_pipeline(
camera_id,
capture_width=1920,
capture_height=1080,
display_width=1920,
display_height=1080,
framerate=30,
flip_method=0,
):
return (
"nvarguscamerasrc sensor-id=%d ! "
"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 max-buffers=1 drop=True"
% (
camera_id,
capture_width,
capture_height,
framerate,
flip_method,
display_width,
display_height,
)
)
stream = cv2.VideoCapture(__gstreamer_pipeline(camera_id=0, flip_method=2), cv2.CAP_GSTREAMER)
我正在尝试在我的 raspberry pi(Ubuntu 系统)上获取脚本 运行ning。现在,我只是在复习 opencv 的基础知识,因为我已经有一段时间没有使用它了。所以我直接从 OpenCV 网站复制粘贴了这段代码,然后 运行 它。
import numpy as np
import cv2 as cv
cap = cv.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
exit()
while True:
# Capture frame-by-frame
ret, frame = cap.read()
# if frame is read correctly ret is True
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
# Our operations on the frame come here
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
# Display the resulting frame
cv.imshow('frame', gray)
if cv.waitKey(1) == ord('q'):
break
# When everything done, release the capture
cap.release()
cv.destroyAllWindows()
只是,运行它给了我一个纯灰色 window 作为弹出窗口并抛出这些错误:
[ WARN:0] global /usr/local/src/opencv-4.4.0/modules/videoio/src/cap_gstreamer.cpp (1761) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Internal data stream error.
[ WARN:0] global /usr/local/src/opencv-4.4.0/modules/videoio/src/cap_gstreamer.cpp (888) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global /usr/local/src/opencv-4.4.0/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
代码仍然 运行,因为我可以通过按 'q' 关闭 window。但是视频流部分出现了严重错误。我什至不知道什么是 GStreamer,更不知道什么是 GStreamer 管道。我不知道如何解决这个问题,也没有在网上找到任何有效的方法。
我的代码在 jetson nano
上运行 运行def __gstreamer_pipeline(
camera_id,
capture_width=1920,
capture_height=1080,
display_width=1920,
display_height=1080,
framerate=30,
flip_method=0,
):
return (
"nvarguscamerasrc sensor-id=%d ! "
"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 max-buffers=1 drop=True"
% (
camera_id,
capture_width,
capture_height,
framerate,
flip_method,
display_width,
display_height,
)
)
stream = cv2.VideoCapture(__gstreamer_pipeline(camera_id=0, flip_method=2), cv2.CAP_GSTREAMER)