VideoCamera#

class VideoCamera(id: int = 0, rgb: bool = True, **kwargs: Any)[source]#

Iterate images from a local video camera

Parameters:
  • id (int) – Identity of local camera

  • kwargs – options applied to image frames, see convert

Connect to a local video camera. For some cameras this will cause the recording light to come on.

The resulting object is an iterator over the frames from the video camera. The iterator returns Image objects.

Example:

from machinevisiontoolbox import VideoCamera
video = VideoCamera(0)
for im in video:
    pass

alternatively:

img = next(video)

or using a context manager to ensure the camera is released:

with VideoCamera(0) as camera:
    for im in camera:
        pass

Note

The value of id is system specific but generally 0 is the first attached video camera. On a Mac running 13.0 (Ventura) or later and an iPhone with iOS 16 or later, the Continuity Camera feature allows the phone camera to be used as a local video camera, and it will appear as a separate camera with its own ID.

OpenCV does not expose a portable API for mapping integer id values to human-readable camera names. Use list to enumerate the cameras that are present on the current machine together with their best-available names.

References:
Seealso:

list convert cv2.VideoCapture

Base constructor for image sources.

Parameters:

kwargs (Any) – source-specific keyword arguments