Improved black point estimation -- favor a point not white so close the white peak

git-svn-id: https://zxing.googlecode.com/svn/trunk@135 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2008-01-07 16:31:26 +00:00
parent 80b3dd3632
commit b112a890fb
2 changed files with 8 additions and 4 deletions

View file

@ -77,11 +77,13 @@ public final class BlackPointEstimator {
// Find a valley between them that is low and closer to the white peak // Find a valley between them that is low and closer to the white peak
int bestValley = secondPeak - 1; int bestValley = secondPeak - 1;
int bestValleyScore = Integer.MAX_VALUE; int bestValleyScore = -1;
for (int i = secondPeak - 1; i > firstPeak; i--) { for (int i = secondPeak - 1; i > firstPeak; i--) {
int distance = secondPeak - i + 3; int fromFirst = i - firstPeak;
int score = distance * histogram[i]; // Favor a "valley" that is not too close to either peak -- especially not the black peak --
if (score < bestValleyScore) { // and that has a low value of course
int score = fromFirst * fromFirst * (secondPeak - i) * (256 - histogram[i]);
if (score > bestValleyScore) {
bestValley = i; bestValley = i;
bestValleyScore = score; bestValleyScore = score;
} }

View file

@ -73,6 +73,8 @@ public final class QRCodeReaderTestCase extends TestCase {
"http://staticrooster.com"); "http://staticrooster.com");
doTestURI("http://www.ihaveanidea.org/blogs/uploads/i/interactive/270.png", doTestURI("http://www.ihaveanidea.org/blogs/uploads/i/interactive/270.png",
"Morden"); "Morden");
doTestURI("http://www.google.co.jp/mobile/images/qrcode_mobile.gif",
"Google \u30e2\u30d0\u30a4\u30eb\r\nhttp://google.jp");
} }
private static void doTestURI(final String uriString, final String expected) private static void doTestURI(final String uriString, final String expected)