CV2 can't read Webcam on MacBook Pro
Question:
OpenCV can’t read my webcam even though I granted permission and the Mac is telling me that Python uses my webcam. It is clearly capturing something and I don’t get an error however the preview window will not open:
When I open an already downloaded picture or mp4 it works without any problems.
I use Python 3.7 and opencv-python-4.5.1.48 on MacOS Big Sur.
EDIT: The exact same code works in BootCamp without problems
Answers:
For an unknown reason, if you installed openCV with pip install opencv-python
, it won’t work with macOS’s privacy policy.
You should instead use the brew package
brew install opencv
# Brew will probably need to overwrite previous openCV installations
brew link --overwrite opencv
As soon as you create the VideoCapture object, your webcam indicator should light up
import cv2
cap = cv2.VideoCapture(0)
OpenCV can’t read my webcam even though I granted permission and the Mac is telling me that Python uses my webcam. It is clearly capturing something and I don’t get an error however the preview window will not open:
When I open an already downloaded picture or mp4 it works without any problems.
I use Python 3.7 and opencv-python-4.5.1.48 on MacOS Big Sur.
EDIT: The exact same code works in BootCamp without problems
For an unknown reason, if you installed openCV with pip install opencv-python
, it won’t work with macOS’s privacy policy.
You should instead use the brew package
brew install opencv
# Brew will probably need to overwrite previous openCV installations
brew link --overwrite opencv
As soon as you create the VideoCapture object, your webcam indicator should light up
import cv2
cap = cv2.VideoCapture(0)