All of the programs you have worked on so far have processed individual images but OpenCV is also able to process videos. Here, you will review (but not modify) a program which processes videos of traffic to detect cars and then count them. This laboratory also helps you gain an important skill that developers and researchers need to have: understand what someone else's code does. You may find this more difficult than you expect!
The zip-file for this experiment
contains a program, carcounter.py
, a video clip,
highway.mp4
, and an associated configuration file,
highway.cfg
. As ever, the configuration file is textual and
you are encouraged to review it as you figure out how the program
works.
To run the program, use the command:
python carcounter.py highway.mp4
You will see that some red regions are marked on the output --- you should examine the program to identify what these represent. Vehicles detected are outlined in green as the program runs and the total car count appears in the top-left corner of the display.
Try to figure out how carcounter.py
works. You should
ask yourself questions such as
What mechanism is used in OpenCV for processing videos?
What video formats are supported by OpenCV?
By what algorithm is a vehicle found?
What do the red regions represent?
Are all vehicles found?
Are vehicles lost and re-acquired?
How does a vehicle contribute to the total given in the top-left corner of the output?
Are some types of vehicles more difficult to find than others?
Does the colour of a vehicle have an effect?
What information is contained in a configuration file?
Why is a configuration file used instead of building the information into the program?
Then take a look at commented.py
, the same program but
with comments. How much easier was the commented version to
understand?
You might reflect on how easy it is for staff to mark students'
submissions to assignments, which are typically more like
carcounter.py
than commented.py
and how good
so-called "self-documenting" code is in general. Feel free to discuss
your findings with a demonstrator.
Web page maintained by Adrian F. Clark using Emacs, the One True Editor ;-) |