Toybrick

opencv无法打开USB摄像头

sunzhongmeng

注册会员

积分
116
楼主
发表于 2019-3-26 14:28:46    查看: 10398|回复: 4 | [复制链接]    打印 | 只看该作者
按照人工智能开发系列(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

注册会员

积分
116
沙发
 楼主| 发表于 2019-3-30 11:16:32 | 只看该作者

你好,这个已经安装了,现在可以打开本地视频,但是USB摄像头还是无法开启(USB摄像头是UVC免驱,且在UBUNTU上验证可用)
回复

使用道具 举报

sunzhongmeng

注册会员

积分
116
板凳
 楼主| 发表于 2019-3-30 12:01:54 | 只看该作者

本地视频可以打开,但是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

中级会员

积分
202
地板
发表于 2019-4-2 10:12:09 | 只看该作者
之前遇到相似的问题, ls /dev/video*看看是不是有多个摄像头设备
如果有多个摄像头设备, USB不一定是video0, 插拔下看下是video#
然后改代码中打开摄像头部分
cap = cv2.VideoCapture(“/dev/video#”)
回复

使用道具 举报

jon

新手上路

积分
40
5#
发表于 2020-8-27 10:10:52 | 只看该作者
4.此时应该可以正常显示图片及打开摄像头,但无法打开视频文件,需安装gstreamer

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

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

产品中心 购买渠道 开源社区 Wiki教程 资料下载 关于Toybrick


快速回复 返回顶部 返回列表