O'Reilly logo

Smart Internet of Things Projects by Agus Kurniawan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Accessing camera modules from the OpenCV library

In the previous section, we used a still image as a source for the OpenCV library. We can use a camera as the source of a still image. A camera generates video data, which is a collection of still images. To access camera modules from the OpenCV library, follow these steps:

  1. To access a camera from OpenCV, we can use the VideoCapture object. We call read() to read a frame, which is a still of a frame.
  2. For a demo, we use the camera USB drive. Just connect this device to the Raspberry Pi board through the USB drive. Then, we write the following scripts with your text editor:
    import numpy as np import cv2 cap = cv2.VideoCapture(0) while True: # Capture frame-by-frame ret, frame = cap.read() # Display the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required