Merge pull request #52 from tgibson11/master

Reduce possibility of detecting white rectangles within barcodes
This commit is contained in:
Sean Owen 2014-02-12 23:32:46 +00:00
commit a8cd708508

View file

@ -88,6 +88,11 @@ public final class WhiteRectangleDetector {
boolean aBlackPointFoundOnBorder = true; boolean aBlackPointFoundOnBorder = true;
boolean atLeastOneBlackPointFoundOnBorder = false; boolean atLeastOneBlackPointFoundOnBorder = false;
boolean atLeastOneBlackPointFoundOnRight = false;
boolean atLeastOneBlackPointFoundOnBottom = false;
boolean atLeastOneBlackPointFoundOnLeft = false;
boolean atLeastOneBlackPointFoundOnTop = false;
while (aBlackPointFoundOnBorder) { while (aBlackPointFoundOnBorder) {
aBlackPointFoundOnBorder = false; aBlackPointFoundOnBorder = false;
@ -96,11 +101,14 @@ public final class WhiteRectangleDetector {
// . | // . |
// ..... // .....
boolean rightBorderNotWhite = true; boolean rightBorderNotWhite = true;
while (rightBorderNotWhite && right < width) { while ((rightBorderNotWhite || !atLeastOneBlackPointFoundOnRight) && right < width) {
rightBorderNotWhite = containsBlackPoint(up, down, right, false); rightBorderNotWhite = containsBlackPoint(up, down, right, false);
if (rightBorderNotWhite) { if (rightBorderNotWhite) {
right++; right++;
aBlackPointFoundOnBorder = true; aBlackPointFoundOnBorder = true;
atLeastOneBlackPointFoundOnRight = true;
} else if (!atLeastOneBlackPointFoundOnRight) {
right++;
} }
} }
@ -113,11 +121,14 @@ public final class WhiteRectangleDetector {
// . . // . .
// .___. // .___.
boolean bottomBorderNotWhite = true; boolean bottomBorderNotWhite = true;
while (bottomBorderNotWhite && down < height) { while ((bottomBorderNotWhite || !atLeastOneBlackPointFoundOnBottom) && down < height) {
bottomBorderNotWhite = containsBlackPoint(left, right, down, true); bottomBorderNotWhite = containsBlackPoint(left, right, down, true);
if (bottomBorderNotWhite) { if (bottomBorderNotWhite) {
down++; down++;
aBlackPointFoundOnBorder = true; aBlackPointFoundOnBorder = true;
atLeastOneBlackPointFoundOnBottom = true;
} else if (!atLeastOneBlackPointFoundOnBottom) {
down++;
} }
} }
@ -130,11 +141,14 @@ public final class WhiteRectangleDetector {
// | . // | .
// ..... // .....
boolean leftBorderNotWhite = true; boolean leftBorderNotWhite = true;
while (leftBorderNotWhite && left >= 0) { while ((leftBorderNotWhite || !atLeastOneBlackPointFoundOnLeft) && left >= 0) {
leftBorderNotWhite = containsBlackPoint(up, down, left, false); leftBorderNotWhite = containsBlackPoint(up, down, left, false);
if (leftBorderNotWhite) { if (leftBorderNotWhite) {
left--; left--;
aBlackPointFoundOnBorder = true; aBlackPointFoundOnBorder = true;
atLeastOneBlackPointFoundOnLeft = true;
} else if (!atLeastOneBlackPointFoundOnLeft) {
left--;
} }
} }
@ -147,11 +161,14 @@ public final class WhiteRectangleDetector {
// . . // . .
// ..... // .....
boolean topBorderNotWhite = true; boolean topBorderNotWhite = true;
while (topBorderNotWhite && up >= 0) { while ((topBorderNotWhite || !atLeastOneBlackPointFoundOnTop) && up >= 0) {
topBorderNotWhite = containsBlackPoint(left, right, up, true); topBorderNotWhite = containsBlackPoint(left, right, up, true);
if (topBorderNotWhite) { if (topBorderNotWhite) {
up--; up--;
aBlackPointFoundOnBorder = true; aBlackPointFoundOnBorder = true;
atLeastOneBlackPointFoundOnTop = true;
} else if (!atLeastOneBlackPointFoundOnTop) {
up--;
} }
} }