Member-only story
How to read images, video, webcam and screen in OpenCV — image analysis for beginners
Step by step guide on how to read images for OpenCV to process
OpenCV is a great tool for getting information from images. In this series, we’ll learn how to process and analyze images so that we can detect movement, patterns, templates and even read texts. Before all that, however, we need images to analyze and that’s what this article is about.
We’ll check out 4 methods of obtaining images for OpenCV to analyze and go through each of them step by step. In the end, you’ll be able to:
- load an image
- load a video file
- read your webcam
- read your screen
- adjust colors
We’ll use this knowledge in the next parts of this series to create some beautiful analyses.
Series
This article is part of a series about OpenCV image processing. Check out the other articles:
- Reading images, video’s, your screen and the webcam (📍 You are here!)
- Detecting and blurring faces
- Destroying Duck Hunt with template matching: finding images in images
- Creating a motion-detector
- Detecting shapes without AI (under construction; coming soon)
- Detecting and reading text from images (under construction; coming soon)
Setup
In this part we’ll install our dependencies and get OpenCV up and running. The goal is to have an image that we can use. We only need to install two dependencies: OpenCV and PIL (Python Image Library). Install them with:
pip install opencv-python pillow
Reading images
We’ll start by simply reading an image from a file. Next we go about “filming” our screen. We can use this for analyzing the images we see on the screen (we’ll get into this later). Lastly we’ll start reading…