Search code examples
c++opencvobject-detection

OpenCV Haar Classifier Threshold


I'm trying to understand the oepncv XML haar classifier which looks like this:

      <_>
      <!-- tree 0 -->
      <_>
        <!-- root node -->
        <feature>
          <rects>
            <_>3 7 14 4 -1.</_>
            <_>3 9 14 2 2.</_></rects>
          <tilted>0</tilted></feature>
        <threshold>4.0141958743333817e-003</threshold>
        <left_val>0.0337941907346249</left_val>
        <right_val>0.8378106951713562</right_val></_></_>

As mentioned in the original paper, the threshold should be compared with the sum of a feature (integral image). However, the pixel values of the image should be 0 - 255 (grey scale image). How could the sum of a feature be that small (e.g. in this feature, the threshold is 0.004014...)? Can you guys give me some directions to understand that?

Thank you for your help!


Solution

  • This problem has been solved. The paper that opencv team published to implement this algorithm has mentioned that they actually normalized the pixels using the following equation:

    Pixel = (Pixel_old - average)/(2*sigma)
    

    Pixel is the normalized value for each pixel, Pixel_old is the original integer value (0-255) average is the average of the detection window( it should be a 20*20 window) sigma is the standard deviation of the pixels in 20*20 window.