Published on: Oct 15, 2024
Haar cascade in C++
Haar cascade is a machine learning-based object detection method used in computer vision and image processing. It is named after the Haar wavelets, which are mathematical functions that form the basis of the Haar cascade algorithm. The Haar cascade algorithm uses a series of simple rectangular filters to detect objects in an image. The filters are applied to the input image in a sliding window manner, and the output of each filter is combined to make a decision about the presence of an object in the current window. The Haar cascade algorithm is fast, efficient, and has been widely used in various applications, such as face detection, license plate recognition, and others.
Getting the program
Download the pretrained cascade detector for opencv git repo. The opencv repo has many pretrained haar detector and I am using one of those in the example below.
Compiling haar C++ program
Go into the haar folder and type:
1mkdir build && cd build 2conan install .. 3cmake .. 4cmake --build . 5
This will build the program. Sometime, you might need to install packages with conan install .. --build=missing option enabled, when precompiled binaries are not available in the conan-center (remote repository).
You can run the haar program from the build folder while passing the pre-trained haar cascade file with the path.
For example:
1bin\haar haarcascade_frontalcatface.xml 2