Search code examples
opencvobject-detectionhaar-classifier

Haar feature implementation on OpenCv


Can someone explain me what the functions in haar.cpp file (in OpenCv) do? And which function actually does the Haar feature evaluation?


Solution

  • This is how HAAR module works in my understanding:

    You need an image and a cascade file. Cascade file contains a "tree". You start at the top of the tree and propagate downwards. Every node specifies what type of haar feature you have to extract and a threshold (http://opencv.jp/opencv-2.2_org/c/objdetect_cascade_classification.html).

    Here is the pseudocode

    1. Take a 2D Image patch where you want to detect an object. Lets say it's size is 64x64 grayscale pixels.

    2. Start propagating the cascade tree, by computing the node's haar-like feature and comparing its value with the threshold stored in the node. If bigger go to the left otherwise go to right, let's say. Continue until a tree leaf is reached.

    If you disable all optimizations, some of this computations happen between lines 797 to 813 haar.cpp.