Skip to content Skip to sidebar Skip to footer

How Do I Access My Usb Camera Using Opencv With Python?

I am having trouble accessing my USB camera using OpenCV with python. I get the following error message which I understand means no frame was captured? error: OpenCV(3.4.1) C:\Mini

Solution 1:

The camera index most of the time is 0 as default with computers which come with an integrated camera, but if you're plugging a USB camera, its camera index could be 1 or 2, you can try with both of them.

But if you wanna get all camera index available, you can use the following simple script to find out:

import cv2
import numpy as np

all_camera_idx_available = []

for camera_idx in range(10):
    cap = cv2.VideoCapture(camera_idx)
    ifcap.isOpened():
        print(f'Camera index available: {camera_idx}')
        all_camera_idx_available.append(camera_idx)
        cap.release()

The result would be a list like: [0,1,2,...] with all camera index available.

But if you're using a USB camera you have to keep in mind that some OpenCV functions won't work, take a look at this.

Post a Comment for "How Do I Access My Usb Camera Using Opencv With Python?"