C++ version of the Sherlock video processing codes using multi-threading and shared memory for high performance on SMP (multi-core or multi-processor) systems.
In order to build the codes, you're gonna need to have a few things available on your system:
- SCons -- excellent Python-based build system
- OpenCV -- the one-and-only image processing library
- Boost C++ libraries -- if it ain't in the C++ standard, it's in Boost
With YUM package manager (Red Hat, CentOS, Fedora):
yum install scons opencv-devel boost-devel
On systems using Aptitude package manager (Debian, Ubuntu):
aptitude install scons libopencv-dev libboost-all-dev
Download the Sherlock C++ codes and the auxiliary Bites tools library, then build the software stack:
git clone https://github.com/vmlaker/sherlock-cpp git clone https://github.com/vmlaker/bites cd sherlock-cpp scons bites=../bites
Test basic functionality by playing live video from
the first device (/dev/video0
) for a duration of 10 seconds:
bin/playcv 0 800 600 10
Objects in the video stream are detected using Haar feature-based
cascade classifiers. Active classifiers are listed in
conf/classifiers.conf
file. By default, these are
vanilla classifiers shipped with OpenCV distribution.
You can edit this file to activate (or deactivate) classifiers,
change search paths, add your own custom classifiers,
and configure global object detection parameters.
The parallel algorithm distributes tasks among multiple threads, a separate thread running one of the following tasks:
- Allocation of frame memory and video capture.
- Object detection (one thread per each Haar classifier.)
- Augmenting output with detection result and displaying the frame.
- Memory deallocation.
Memory for every captured frame is shared between all threads. You can run the object detection algorithm with:
bin/detect 0 800 600 10
Motion detection is implemented with a run-of-the-mill
foreground/background segmentation algorithm using scene average.
Each iteration of diffavg
code increases in complexity,
with cumulative changes intended to enhance performance.
You can compare processing performace by comparing framerates
(displayed in upper left corner) for different cases.
Try running at high (at or near maximum) resolution of your camera.
Also, consider profiling resource usage by running the codes
prefixed with the time
command.
First, run the baseline case, a sequential implementation of the algorithm:
bin/diffavg1 0 800 600 10
Now let's try the multi-threaded version utilizing shared memory. Increased performance gained from parallel threads will only be realized on SMP machines.
bin/diffavg2 0 800 600 10
In case your display hardware does not keep up with the capture and processing framerate, you may experience incremental lag in playback of the previous case. The following case implements lossy filtering of excess frames in the display pipeline, resulting in a more "realtime" feel of the final output:
bin/diffavg3 0 800 600 10
To revert your repo to a clean state (like it was before the build) just do:
scons -c