OpenCV can't open the webcam

  • Python
  • OpenCV

You may see

cap.isOpened() is False
Cannot open webcam
can't open camera by index
obsensor_uvc_stream_channel.cpp
Camera index out of range

Why it happens

  • Another app is using it.
  • The number is wrong.
  • Windows or macOS blocks the camera.

How to fix it

  1. Close Zoom, Teams and other Python windows.
  2. Try cv2.VideoCapture(1), then 2.
  3. On Windows try cv2.VideoCapture(0, cv2.CAP_DSHOW).
  4. Allow the camera in the system's privacy settings.
  5. Call cap.release() at the end of each program.

It worked if: cap.isOpened() prints True.

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.