我正在尝试在我的raspberry pi(Ubuntu系统)上运行一个脚本。现在,我正在刷新自己对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()
只是,运行它给了我一个坚实的灰色窗口作为一个弹出窗口,并抛出这些错误:
[ 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”关闭窗口。但是视频流部分出现了可怕的错误。我甚至不知道GStreamer是什么,更不用说GStreamer管道是什么了。我不知道如何修复这个问题,也没有在网上找到任何有效的东西。
1条答案
按热度按时间oiopk7p51#
我的代码在Jetson nano上运行正常