网络摄像头在opencv-python和opencv-contrib-python的pip版本中不起作用 [英] webcam does not work in pip version of opencv-python and opencv-contrib-python

查看:206
本文介绍了网络摄像头在opencv-python和opencv-contrib-python的pip版本中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用蟒蛇的python中的opencv中遇到了网络摄像头问题.

I've been facing a problem with the webcam in opencv in python using anaconda.

问题如下: 如果通过以下两种方式之一安装了opencv,则无法打开网络摄像头:
pip install opencv-python(可用的3.1、3.2、3.3)或
pip install opencv-contrib-python(可用3.2,3.3)

The problem is the following: I cannot open the webcam if opencv is installed via any of the two:
pip install opencv-python (available 3.1,3.2,3.3), or
pip install opencv-contrib-python (available 3.2,3.3)

但是只有当我从
安装时,它才能工作 conda install opencv(可用的opencv 3.1)

However it will work if and only if I install it from
conda install opencv (available opencv 3.1)

但是,opencv的某些功能仅在较新版本中或在conda中当前不可用的contrib版本中提供. 有谁知道为什么pip版本不起作用?

However, some functionality of opencv is only given in newer versions or in the contrib version currently not available via conda. Does anyone have an idea why the pip versions won't work?

更新=> pypi上的Pip包装未与FFMPEG for Linux链接:
conda install -c conda-forge opencv提供3.3,但无贡献
=>如果需要其他版本,则需要从源代码构建

Update => The Pip Packgage on pypi is not linked against FFMPEG for linux:
conda install -c conda-forge opencv provides 3.3 but without contrib
=> if other version is needed building from source is required

以下是用于使用网络摄像头的代码: (是的,我尝试了各种变体

Here the code used to use the webcam: (Yes I tried various variations suggested

import cv2
print (cv2.__version__)
camera = cv2.VideoCapture(0) #tried -1,0,1,...

if camera.isOpened(): # isOpened is always False for pip version
    print ("successfully opened Webcam")
else:
    print ("Webcam error")  
success,img = camera.read() # success is always False for pip version
print (success,img.shape)
camera.release()


我尝试了各种网络摄像头,并按照网络上的建议对代码进行了各种改动.


I tried various webcams, and various alternations to the code as suggested on the web.

推荐答案

底层库未在pip包中链接.这是使软件包可以更通用地安装的设计选择.

The underlying libraries are not linked in the pip package. This was a design choice for the package to be more universally installable.

来自Python包索引(PyPI) opencv-python包的文档 :

From the Python Package Index (PyPI) documentation for the opencv-python package:

问:为什么我不能在GNU/Linux发行版X或macOS上打开视频文件?

A:OpenCV视频I/O在很大程度上取决于FFmpeg.并没有针对许多Linux和macOS OpenCV二进制文件进行编译.这些软件包的目的是为OpenCV Python绑定提供尽可能简单的安装体验,它们应立即可用.在没有通用" FFmpeg构建(例如Windows轮子中的LGPL许可构建)的情况下,将FFmpeg添加为附加依赖项,就很难实现该目标.将来可能会改变.

A: OpenCV video I/O depends heavily on FFmpeg. Manylinux and macOS OpenCV binaries are not compiled against it. The purpose of these packages is to provide as easy as possible installation experience for OpenCV Python bindings and they should work directly out-of-the-box. Adding FFmpeg as an additional dependency without a "universal" FFmpeg build (e.g. LGPL licensed build like in the Windows wheels) the goal is considerably harder to achieve. This might change in the future.

如果您想使用较新的版本并且没有这些问题,则可以从源代码编译OpenCV.有很多这样的教程. OpenCV具有Python专用教程,可用于在Windows上编译在Fedora上.此外,PyImageSearch上有许多关于在macOS和Linux上从源代码编译OpenCV的博客文章:

You could compile OpenCV from source if you want to use the newer versions and not have these problems. There's a number of such tutorials. OpenCV has a Python specific tutorial for compiling on Windows and on Fedora. Additionally, PyImageSearch has a very popular number of blog posts on compiling OpenCV from source on macOS and Linux: Ubuntu 16.04, Ubuntu 14.04, macOS, macOS via Homebrew (with an accompanying troubleshooting article), along with a number of other Linux flavors (e.g. Raspbian) and posts for older Python versions; just search the web if that doesn't cover you.

这篇关于网络摄像头在opencv-python和opencv-contrib-python的pip版本中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆