webcam does not work in pip version of opencv-python and opencv-contrib-python

…衆ロ難τιáo~ 提交于 2019-12-01 11:51:25

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

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

Q: Why I can’t open video files on GNU/Linux distribution X or on macOS?

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!