Toybrick

标题: opencv无法打开USB摄像头 [打印本页]

作者: sunzhongmeng    时间: 2019-3-26 14:28
标题: opencv无法打开USB摄像头
按照人工智能开发系列(3) YOLOV3开发与实现这个帖子搭建的环境,执行
  1. sudo dnf install gstreamer-rockchip
复制代码
后,无法打开UVC摄像头:camera.py:

  1. import numpy as np
  2. import cv2
  3. import matplotlib.pyplot as plot
  4. cap = cv2.VideoCapture(0)
  5. while(True):
  6. ret,frame = cap.read()
  7. cv2.imshow("capture",frame)
  8. if cv2.waitKey(1) & 0xFF == ord('q'):
  9.        break
  10. cap.release()
复制代码

执行:python camera.py
  1. OpenCV(3.4.1) Error: Unspecified error (GStreamer: unable to start pipeline
  2. ) in cvCaptureFromCAM_GStreamer, file /builddir/build/BUILD/opencv-3.4.1/modules/videoio/src/cap_gstreamer.cpp, line 890
  3. VIDEOIO(cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L2, reinterpret_cast<char *>(index))): raised OpenCV exception:

  4. OpenCV(3.4.1) /builddir/build/BUILD/opencv-3.4.1/modules/videoio/src/cap_gstreamer.cpp:890: error: (-2) GStreamer: unable to start pipeline
  5. in function cvCaptureFromCAM_GStreamer

  6. OpenCV(3.4.1) Error: Unspecified error (unicap: failed to get info for device
  7. ) in CvCapture_Unicap::initDevice, file /builddir/build/BUILD/opencv-3.4.1/modules/videoio/src/cap_unicap.cpp, line 139
  8. VIDEOIO(cvCreateCameraCapture_Unicap(index)): raised OpenCV exception:

  9. OpenCV(3.4.1) /builddir/build/BUILD/opencv-3.4.1/modules/videoio/src/cap_unicap.cpp:139: error: (-2) unicap: failed to get info for device
  10. in function CvCapture_Unicap::initDevice

  11. OpenCV(3.4.1) Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /builddir/build/BUILD/opencv-3.4.1/modules/highgui/src/window.cpp, line 364
  12. Traceback (most recent call last):
  13.   File "camera.py", line 7, in <module>
  14.     cv2.imshow("capture",frame)
  15. cv2.error: OpenCV(3.4.1) /builddir/build/BUILD/opencv-3.4.1/modules/highgui/src/window.cpp:364: error: (-215) size.width>0 && size.height>0 in function imshow
复制代码
本地视频也无法打开!



作者: sunzhongmeng    时间: 2019-3-30 11:16
hisping 发表于 2019-3-27 20:51
试下

你好,这个已经安装了,现在可以打开本地视频,但是USB摄像头还是无法开启(USB摄像头是UVC免驱,且在UBUNTU上验证可用)
作者: sunzhongmeng    时间: 2019-3-30 12:01
hisping 发表于 2019-3-27 20:51
试下

本地视频可以打开,但是USB免驱摄像头还是无法打开
  1. OpenCV(3.4.1) Error: Unspecified error (GStreamer: unable to start pipeline
  2. ) in cvCaptureFromCAM_GStreamer, file /builddir/build/BUILD/opencv-3.4.1/modules/videoio/src/cap_gstreamer.cpp, line 890
  3. VIDEOIO(cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L2, reinterpret_cast<char *>(index))): raised OpenCV exception:

  4. OpenCV(3.4.1) /builddir/build/BUILD/opencv-3.4.1/modules/videoio/src/cap_gstreamer.cpp:890: error: (-2) GStreamer: unable to start pipeline
  5. in function cvCaptureFromCAM_GStreamer

  6. OpenCV(3.4.1) Error: Unspecified error (unicap: failed to get info for device
  7. ) in CvCapture_Unicap::initDevice, file /builddir/build/BUILD/opencv-3.4.1/modules/videoio/src/cap_unicap.cpp, line 139
  8. VIDEOIO(cvCreateCameraCapture_Unicap(index)): raised OpenCV exception:

  9. OpenCV(3.4.1) /builddir/build/BUILD/opencv-3.4.1/modules/videoio/src/cap_unicap.cpp:139: error: (-2) unicap: failed to get info for device
  10. in function CvCapture_Unicap::initDevice

  11. OpenCV(3.4.1) Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /builddir/build/BUILD/opencv-3.4.1/modules/highgui/src/window.cpp, line 364
  12. Traceback (most recent call last):
  13.   File "open_camera.py", line 13, in <module>
  14.     video_demo()
  15.   File "open_camera.py", line 7, in video_demo
  16.     cv.imshow("UVC",frame)
  17. cv2.error: OpenCV(3.4.1) /builddir/build/BUILD/opencv-3.4.1/modules/highgui/src/window.cpp:364: error: (-215) size.width>0 && size.height>0 in function imshow
复制代码



作者: eeyeh    时间: 2019-4-2 10:12
之前遇到相似的问题, ls /dev/video*看看是不是有多个摄像头设备
如果有多个摄像头设备, USB不一定是video0, 插拔下看下是video#
然后改代码中打开摄像头部分
cap = cv2.VideoCapture(“/dev/video#”)
作者: jon    时间: 2020-8-27 10:10
4.此时应该可以正常显示图片及打开摄像头,但无法打开视频文件,需安装gstreamer

    sudo dnf install https://download1.rpmfusion.org/ ... usion-free-release-$(rpm -E %fedora).noarch.rpm
    sudo dnf install gstreamer1-libav




欢迎光临 Toybrick (https://t.rock-chips.com/) Powered by Discuz! X3.3