// The relationship between the white and the black part in a traditional // Haar-like feature could be much more general. Why do they have to // touch each other? Why do they need to have the same aspect ratio? // All we require is white area = black area so the subtraction makes sense. // // And even that could be lifted by applying a correction factor // (area white / area black). // // [We should generally start normalizing the result between -1 // (maximum inverted match) and 1 (maximum direct match) at this point // as now we have two different areas in play so we can't really return // meaningful "pixels" anymore.] // // Finally, black and white can even overlap and the formula doesn't even change. // Although you may want to boost the result value because it's never // going to reach -1 or 1 when there is overlap. Not sure how to do // the actual calculation for that. // // So these are... "generalized Haar features"? // // Result classification: // // positive = match // 0 = non-match (indifferent/not applicable) // negative = anti-match (inverted Haar feature found) srecord Haar(IIntegralImage img, DoubleRect rBlack, DoubleRect rWhite) { double get() { double blackArea = area(rBlack); double whiteArea = area(rWhite); //double overlappingArea = area(intersectDoubleRects(rBlack, rWhite)); //double boost = ? double whiteSum = img.pixelSum(rWhite); // this is between 0 and whiteArea*255 double blackSum = img.pixelSum(rBlack); // this is between 0 and blackArea*255 ret (doubleRatio(whiteSum, whiteArea) - doubleRatio(blackSum, blackArea))/255.0; } }