# OpenCV VideoCapture cannot open the camera: index, backend and permissions

> Fix OpenCV that cannot open a webcam: try camera index 0, 1 or 2, use the DirectShow backend on Windows and close other apps using the camera.

Canonical: https://roboticsengineering.in/fix/opencv-cannot-open-camera-wrong-index/ | Published: 2026-11-03 | Updated: 2026-11-04

**Check the camera index first. VideoCapture(0) is the first camera, and a second camera is often 1.**

## What the message means

OpenCV opens the camera by number and backend. A laptop with a built-in camera and a USB camera has two numbers, and another app may already hold the device.

## Fix it in this order

1. Try VideoCapture(0), then 1 and 2, and test cap.isOpened().
2. On Windows try cv2.VideoCapture(index, cv2.CAP_DSHOW).
3. Close other apps that use the camera, such as video call programs.
4. Allow camera access for your terminal or editor in the system privacy settings.
5. Check cap.read() returns True before you use the frame.
6. On Linux check the device with ls /dev/video\*.

## Why it happens

OpenCV opens a camera by number, and the numbers depend on the devices your system lists. A laptop with a built-in camera and a USB camera has two, and which is zero can change when devices are plugged in or out.

Only one program can usually use a camera at a time, so another app that is running can block it. The backend matters on some systems, which is why the page suggests trying another one on Windows. Test isOpened() before you read frames.

## If you see this, do this

| You see | Do this |
| --- | --- |
| isOpened is False | Index, backend or permissions. |
| Opens but frame is None | Another app or a faulty cable. |

## Related

[camera calibration with OpenCV](https://roboticsengineering.in/camera-calibration-opencv-python/), [imshow black or frozen](https://roboticsengineering.in/fix/opencv-imshow-window-black-or-freezes/).

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.

## Why this happens

VideoCapture(0) asks the operating system for the first camera through a backend (DirectShow or Media Foundation on Windows, V4L2 on Linux, AVFoundation on macOS). The call returns an object even when it failed, so the failure only shows later as isOpened() being False or read() returning no frame. Index numbers are assigned by the system, and a virtual camera, a laptop webcam or a second USB camera can take 0 and push yours to 1 or 2.

On Linux the device file must be readable by your user, normally by being in the video group. A camera can also be opened by only one program at a time, so a browser tab or a leftover Python process can block it. On Raspberry Pi OS the ribbon-cable camera uses libcamera and is not a plain V4L2 device, so VideoCapture(0) usually does not see it; Picamera2 is used instead.

## How to confirm the cause

- Print `cap.isOpened()` and also the pair returned by `cap.read()`. Opened but no frame is a different fault from not opened.
- Loop over indexes 0 to 3 and print which ones open, as in the example. Use the one that returns a frame.
- On Linux run `ls -l /dev/video*` and `groups`. No device file means the system does not see the camera; a file without your group means a permission fix.
- Close other camera users (video calls, browsers, other scripts) and try again.
- Try an explicit backend such as CAP_DSHOW on Windows or CAP_V4L2 on Linux.

## Worked example

A scan of the first four indexes with an explicit backend. Change the backend constant for your system.

```
import cv2

for i in range(4):
    cap = cv2.VideoCapture(i, cv2.CAP_DSHOW)   # Linux: cv2.CAP_V4L2
    ok, frame = cap.read()
    print(i, cap.isOpened(), ok,
          None if frame is None else frame.shape)
    cap.release()
```

## Common mistakes

- Never checking the return value of read(), then crashing later on a None frame.
- Passing the device path to a build or backend that expects an integer index, or the reverse.
- Running the script inside WSL or a container that cannot see the USB camera.
- Plugging a camera into an unpowered hub that cannot supply enough current.
- Calling release() never, so a crashed script keeps the camera locked.

## If this did not fix it

- The camera works in the system camera app but not in Python: privacy settings may block desktop apps.
- The wrong OpenCV package: some builds lack the backend you need.
- A cable or port that carries power but poor data; try another port directly on the machine.
- The requested resolution or format is not supported; try without setting width and height.
