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
Imageobjects.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: # process image
Note
The value of
idis 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
idvalues to human-readable camera names. Uselistto enumerate the cameras that are present on the current machine together with their best-available names.- References:
P. Corke, Robotics, Vision & Control for Python, Springer, 2023, Section 11.1.3.
- Seealso:
Base constructor for image sources.
- Parameters:
kwargs (Any) – source-specific keyword arguments
Methods
Display images from the source interactively.
Get camera property
Grab single frame from camera
Enumerate available local video cameras
Release the camera
Set camera property
Convert all images from this source into a single 4D PyTorch tensor.
Attributes