I\'ve been facing a problem with the webcam in opencv in python using anaconda.
The problem is the following: I cannot open the webcam if opencv is installed via any
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.
Just uninstall the opencv-contrib-python libary, and re-install opencv-python and opencv-python-headless