Skip to content

Workbench article

Reading Local Cameras

3. Reading Local Cameras

The core tool in OpenCV for camera access is cv2.VideoCapture. It seems simple, but there are many hidden properties that can make or break your performance.

import cv2
cap = cv2.VideoCapture(0)
if not cap.isOpened():
    print("Error: Could not open camera.")

3.1 Setting Resolution and FPS

Never assume the camera will give you the requested resolution. Always "Set" then "Get" to verify.

cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
print(f"Actual Width: {width}")