OpenCV can't open the webcam
- Python
- OpenCV
You may see
Why it happens
- Another app is using it.
- The number is wrong.
- Windows or macOS blocks the camera.
How to fix it
- Close Zoom, Teams and other Python windows.
- Try
cv2.VideoCapture(1), then 2. - On Windows try
cv2.VideoCapture(0, cv2.CAP_DSHOW). - Allow the camera in the system's privacy settings.
- Call
cap.release()at the end of each program.
It worked if: cap.isOpened() prints True.
Related errors
Seen in a real run (some lines are close variants of it). Produced with Python 3.13 and OpenCV 5.1 on Windows. Asked for camera 9: isOpened() was False and read() gave (False, None).
Didn't help? Search another error or ask us.

