在Ubuntu上运行OpenCV时出现GStreamer警告

ruoxqz4g  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(1171)

我正在尝试在我的raspberry pi(Ubuntu系统)上运行一个脚本。现在,我正在刷新自己对opencv的基础知识,因为我已经有一段时间没有使用它了。所以我直接从OpenCV网站上复制粘贴了这段代码并运行了它。

  1. import numpy as np
  2. import cv2 as cv
  3. cap = cv.VideoCapture(0)
  4. if not cap.isOpened():
  5. print("Cannot open camera")
  6. exit()
  7. while True:
  8. # Capture frame-by-frame
  9. ret, frame = cap.read()
  10. # if frame is read correctly ret is True
  11. if not ret:
  12. print("Can't receive frame (stream end?). Exiting ...")
  13. break
  14. # Our operations on the frame come here
  15. gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
  16. # Display the resulting frame
  17. cv.imshow('frame', gray)
  18. if cv.waitKey(1) == ord('q'):
  19. break
  20. # When everything done, release the capture
  21. cap.release()
  22. cv.destroyAllWindows()

只是,运行它给了我一个坚实的灰色窗口作为一个弹出窗口,并抛出这些错误:

  1. [ 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.
  2. [ 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
  3. [ 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管道是什么了。我不知道如何修复这个问题,也没有在网上找到任何有效的东西。

oiopk7p5

oiopk7p51#

我的代码在Jetson nano上运行正常

  1. def __gstreamer_pipeline(
  2. camera_id,
  3. capture_width=1920,
  4. capture_height=1080,
  5. display_width=1920,
  6. display_height=1080,
  7. framerate=30,
  8. flip_method=0,
  9. ):
  10. return (
  11. "nvarguscamerasrc sensor-id=%d ! "
  12. "video/x-raw(memory:NVMM), "
  13. "width=(int)%d, height=(int)%d, "
  14. "format=(string)NV12, framerate=(fraction)%d/1 ! "
  15. "nvvidconv flip-method=%d ! "
  16. "video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
  17. "videoconvert ! "
  18. "video/x-raw, format=(string)BGR ! appsink max-buffers=1 drop=True"
  19. % (
  20. camera_id,
  21. capture_width,
  22. capture_height,
  23. framerate,
  24. flip_method,
  25. display_width,
  26. display_height,
  27. )
  28. )
  29. stream = cv2.VideoCapture(__gstreamer_pipeline(camera_id=0, flip_method=2), cv2.CAP_GSTREAMER)
展开查看全部

相关问题