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 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)
However it will work if and only if I install it from
conda install opencv
(available opencv 3.1)
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?
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.