Latest Page Update: 23-09-2026
Solution is now available! Download the full solution from here: Solution
Exercise2b - Change detection in videos¶
The goal of this exercise is to create a small program for real-time change detection using OpenCV.
Learning Objectives¶
After completing this exercise, the student should be able to do the following:
- Use OpenCV to access a web-camera or the camera or a mobile phone.
- Use the OpenCV function
cvtColorto convert from color to gray scale, - Convert images from integer to floating point using the
img_as_floatfunction. - Convert image from floating point to uint8 using the
img_as_ubytefunction. - Compute a floating point absolute difference image between a new and a previous image.
- Compute the frames-per-second of an image analysis system.
- Show text on an image using the OpenCV function
putText. - Display an image and zoom on pixel values using the OpenCV function
imshow. - Implement and test a change detection program.
- Update a background image using a linear combination of the previous background image and a new frame.
- Compute a binary image by thresholding an absolute difference image.
- Compute the total number of changed pixels in a binary image.
- Implement a simple decision algorithm that is based on counting the amount of changed pixels in an image.
Installing Python packages¶
In this exercise, we will be using the popular OpenCV library to perform real-time image analysis.
We will use the virtual environment from the previous exercise (course02503). Start an Anaconda prompt and do:
Exercise data and material¶
Download the data you'll need for this exercise by clicking here: Data
Alternatively, you can also fetch the data for the whole course through the Image Analysis GitHub repository. See the Data and GitHub section for more information. If you're using Git, it may be wise run:
git pull
As this will fetch updates to the material, which may happen throughout the course.