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

@ -44,7 +44,7 @@ public final class WhiteRectangleDetector {
private final int upInit;
public WhiteRectangleDetector(BitMatrix image) throws NotFoundException {
this(image, INIT_SIZE, image.getWidth() / 2, image.getHeight() / 2);
this(image, INIT_SIZE, image.getWidth() / 2, image.getHeight() / 2);
}
/**
@ -87,6 +87,11 @@ public final class WhiteRectangleDetector {
boolean sizeExceeded = false;
boolean aBlackPointFoundOnBorder = true;
boolean atLeastOneBlackPointFoundOnBorder = false;
boolean atLeastOneBlackPointFoundOnRight = false;
boolean atLeastOneBlackPointFoundOnBottom = false;
boolean atLeastOneBlackPointFoundOnLeft = false;
boolean atLeastOneBlackPointFoundOnTop = false;
while (aBlackPointFoundOnBorder) {
@ -96,11 +101,14 @@ public final class WhiteRectangleDetector {
// . |
// .....
boolean rightBorderNotWhite = true;
while (rightBorderNotWhite && right < width) {
while ((rightBorderNotWhite || !atLeastOneBlackPointFoundOnRight) && right < width) {
rightBorderNotWhite = containsBlackPoint(up, down, right, false);
if (rightBorderNotWhite) {
right++;
aBlackPointFoundOnBorder = true;
atLeastOneBlackPointFoundOnRight = true;
} else if (!atLeastOneBlackPointFoundOnRight) {
right++;
}
}
@ -113,11 +121,14 @@ public final class WhiteRectangleDetector {
// . .
// .___.
boolean bottomBorderNotWhite = true;
while (bottomBorderNotWhite && down < height) {
while ((bottomBorderNotWhite || !atLeastOneBlackPointFoundOnBottom) && down < height) {
bottomBorderNotWhite = containsBlackPoint(left, right, down, true);
if (bottomBorderNotWhite) {
down++;
aBlackPointFoundOnBorder = true;
atLeastOneBlackPointFoundOnBottom = true;
} else if (!atLeastOneBlackPointFoundOnBottom) {
down++;
}
}
@ -130,11 +141,14 @@ public final class WhiteRectangleDetector {
// | .
// .....
boolean leftBorderNotWhite = true;
while (leftBorderNotWhite && left >= 0) {
while ((leftBorderNotWhite || !atLeastOneBlackPointFoundOnLeft) && left >= 0) {
leftBorderNotWhite = containsBlackPoint(up, down, left, false);
if (leftBorderNotWhite) {
left--;
aBlackPointFoundOnBorder = true;
atLeastOneBlackPointFoundOnLeft = true;
} else if (!atLeastOneBlackPointFoundOnLeft) {
left--;
}
}
@ -147,11 +161,14 @@ public final class WhiteRectangleDetector {
// . .
// .....
boolean topBorderNotWhite = true;
while (topBorderNotWhite && up >= 0) {
while ((topBorderNotWhite || !atLeastOneBlackPointFoundOnTop) && up >= 0) {
topBorderNotWhite = containsBlackPoint(left, right, up, true);
if (topBorderNotWhite) {
up--;
aBlackPointFoundOnBorder = true;
atLeastOneBlackPointFoundOnTop = true;
} else if (!atLeastOneBlackPointFoundOnTop) {
up--;
}
}
@ -163,8 +180,8 @@ public final class WhiteRectangleDetector {
if (aBlackPointFoundOnBorder) {
atLeastOneBlackPointFoundOnBorder = true;
}
}
}
if (!sizeExceeded && atLeastOneBlackPointFoundOnBorder) {
@ -318,4 +335,4 @@ public final class WhiteRectangleDetector {
return false;
}
}
}