Capture Webcam Images with Python and OpenCV

The following code shows how to read a video frame from the webcam.

This assumes the OpenCV library for computer vision is installed. See the post on Installing OpenCV on macOS if needed.

To capture one image:

import cv2
import matplotlib.pyplot as pyplot

captureObject = cv2.VideoCapture(0)

success, testImage =

# See image numeric values.

# Plot image.
pyplot.imshow(testImage, cmap='gray')

To capture many images continuously, we just need to call read() in a loop.


Leave a Reply

Your email address will not be published. Required fields are marked *