WebCam#

class WebCam(url: str, **kwargs: Any)[source][source]#

Iterate images from an internet web camera

Parameters:
  • url (str) – URL of the camera

  • kwargs – options applied to image frames, see convert

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

Example:

from machinevisiontoolbox import WebCam
webcam = WebCam('https://webcam.dartmouth.edu/webcam/image.jpg')
for image in webcam:  # iterate over frames
    pass

alternatively:

img = next(webcam)  # get next frame

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

with WebCam('https://webcam.dartmouth.edu/webcam/image.jpg') as webcam:
    for image in webcam:
        pass

Note

Many webcameras accept a query string in the URL to specify image resolution, image format, codec and other parameters. There is no common standard for this, see the manufacturer’s datasheet for details.

Note

The url is passed to cv2.VideoCapture, so it can be anything that OpenCV can open, for example a still-image URL, a live HTTP (MJPEG) stream or an RTSP stream. A phone can be used as a networked camera in this way: many IP-camera apps for iOS and Android publish a live stream at a URL. Which stream types and URL formats are supported depends on the app and on how your OpenCV was built. On a Mac with an iPhone, Continuity Camera makes the phone appear as a local camera instead, see VideoCamera.

References:
Seealso:

VideoCamera convert cv2.VideoCapture

Base constructor for image sources.

Parameters:

kwargs (Any) – source-specific keyword arguments