Libraryless. Click here for Pure Java version (5184L/31K/105K).
// 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; } }
Began life as a copy of #1009142
download show line numbers debug dex old transpilations
Travelled to 5 computer(s): bhatertpkbcr, iveijnkanddl, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
Snippet ID: | #1032466 |
Snippet name: | Haar - generalized Haar-like feature |
Eternal ID of this version: | #1032466/24 |
Text MD5: | e07a1d136ce35d3765902d2e945ef70f |
Transpilation MD5: | 2b3c464fc60b08173eec59f0142c1b82 |
Author: | stefan |
Category: | javax / imaging |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-09-09 18:45:57 |
Source code size: | 1671 bytes / 39 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 205 / 374 |
Version history: | 23 change(s) |
Referenced in: | [show references] |