This commit is contained in:
Henry Schimke
2022-08-20 14:32:16 -05:00
parent 90ace738b7
commit a6f0b0fd42
2 changed files with 386 additions and 282 deletions

View File

@@ -15,9 +15,8 @@
*/ */
//package com.google.zxing.common.detector; //package com.google.zxing.common.detector;
use crate::{NotFoundException,RXingResultPoint};
use crate::common::BitMatrix; use crate::common::BitMatrix;
use crate::{NotFoundException, RXingResultPoint};
/** /**
* <p>A somewhat generic detector that looks for a barcode-like rectangular region within an image. * <p>A somewhat generic detector that looks for a barcode-like rectangular region within an image.
@@ -27,15 +26,19 @@ use crate::common::BitMatrix;
* @author Sean Owen * @author Sean Owen
* @deprecated without replacement since 3.3.0 * @deprecated without replacement since 3.3.0
*/ */
@Deprecated #[deprecated]
public final class MonochromeRectangleDetector { pub struct MonochromeRectangleDetector {
MAX_MODULES: i32,
private static final int MAX_MODULES = 32; image: BitMatrix,
}
private final BitMatrix image; impl MonochromeRectangleDetector {
pub fn new(image: &BitMatrix) -> Self {
public MonochromeRectangleDetector(BitMatrix image) { Self {
this.image = image; MAX_MODULES: 32,
image: image,
}
} }
/** /**
@@ -48,36 +51,81 @@ public final class MonochromeRectangleDetector {
* third, the rightmost * third, the rightmost
* @throws NotFoundException if no Data Matrix Code can be found * @throws NotFoundException if no Data Matrix Code can be found
*/ */
public RXingResultPoint[] detect() throws NotFoundException { pub fn detect() -> Result<Vec<RXingResultPoint>, NotFoundException> {
int height = image.getHeight(); let height = image.getHeight();
int width = image.getWidth(); let width = image.getWidth();
int halfHeight = height / 2; let halfHeight = height / 2;
int halfWidth = width / 2; let halfWidth = width / 2;
int deltaY = Math.max(1, height / (MAX_MODULES * 8)); let deltaY = Math.max(1, height / (MAX_MODULES * 8));
int deltaX = Math.max(1, width / (MAX_MODULES * 8)); let deltaX = Math.max(1, width / (MAX_MODULES * 8));
int top = 0; let top = 0;
int bottom = height; let bottom = height;
int left = 0; let left = 0;
int right = width; let right = width;
RXingResultPoint pointA = findCornerFromCenter(halfWidth, 0, left, right, let pointA = findCornerFromCenter(
halfHeight, -deltaY, top, bottom, halfWidth / 2); halfWidth,
top = (int) pointA.getY() - 1; 0,
RXingResultPoint pointB = findCornerFromCenter(halfWidth, -deltaX, left, right, left,
halfHeight, 0, top, bottom, halfHeight / 2); right,
left = (int) pointB.getX() - 1; halfHeight,
RXingResultPoint pointC = findCornerFromCenter(halfWidth, deltaX, left, right, -deltaY,
halfHeight, 0, top, bottom, halfHeight / 2); top,
right = (int) pointC.getX() + 1; bottom,
RXingResultPoint pointD = findCornerFromCenter(halfWidth, 0, left, right, halfWidth / 2,
halfHeight, deltaY, top, bottom, halfWidth / 2); );
bottom = (int) pointD.getY() + 1; top = pointA.getY() - 1;
let pointB = findCornerFromCenter(
halfWidth,
-deltaX,
left,
right,
halfHeight,
0,
top,
bottom,
halfHeight / 2,
);
left = pointB.getX() - 1;
let pointC = findCornerFromCenter(
halfWidth,
deltaX,
left,
right,
halfHeight,
0,
top,
bottom,
halfHeight / 2,
);
right = pointC.getX() + 1;
let pointD = findCornerFromCenter(
halfWidth,
0,
left,
right,
halfHeight,
deltaY,
top,
bottom,
halfWidth / 2,
);
bottom = pointD.getY() + 1;
// Go try to find point A again with better information -- might have been off at first. // Go try to find point A again with better information -- might have been off at first.
pointA = findCornerFromCenter(halfWidth, 0, left, right, pointA = findCornerFromCenter(
halfHeight, -deltaY, top, bottom, halfWidth / 4); halfWidth,
0,
left,
right,
halfHeight,
-deltaY,
top,
bottom,
halfWidth / 4,
);
return new RXingResultPoint[] { pointA, pointB, pointC, pointD }; return Vec!([pointA, pointB, pointC, pointD]);
} }
/** /**
@@ -98,20 +146,22 @@ public final class MonochromeRectangleDetector {
* @return a {@link RXingResultPoint} encapsulating the corner that was found * @return a {@link RXingResultPoint} encapsulating the corner that was found
* @throws NotFoundException if such a point cannot be found * @throws NotFoundException if such a point cannot be found
*/ */
private RXingResultPoint findCornerFromCenter(int centerX, fn findCornerFromCenter(
int deltaX, centerX: i32,
int left, deltaX: i32,
int right, left: i32,
int centerY, right: i32,
int deltaY, centerY: i32,
int top, deltaY: i32,
int bottom, top: i32,
int maxWhiteRun) throws NotFoundException { bottom: i32,
int[] lastRange = null; maxWhiteRun: i32,
for (int y = centerY, x = centerX; ) -> Result<RXingResultPoint, NotFoundException> {
y < bottom && y >= top && x < right && x >= left; lastRange = null;
y += deltaY, x += deltaX) { let y: i32 = centerY;
int[] range; let x: i32 = centerX;
while (y < bottom && y >= top && x < right && x >= left) {
let range: Vec::new();
if (deltaX == 0) { if (deltaX == 0) {
// horizontal slices, up and down // horizontal slices, up and down
range = blackWhiteRange(y, maxWhiteRun, left, right, true); range = blackWhiteRange(y, maxWhiteRun, left, right, true);
@@ -121,35 +171,43 @@ public final class MonochromeRectangleDetector {
} }
if (range == null) { if (range == null) {
if (lastRange == null) { if (lastRange == null) {
throw NotFoundException.getNotFoundInstance(); return Err(NotFoundException.getNotFoundInstance());
} }
// lastRange was found // lastRange was found
if (deltaX == 0) { if (deltaX == 0) {
int lastY = y - deltaY; let lastY = y - deltaY;
if (lastRange[0] < centerX) { if (lastRange[0] < centerX) {
if (lastRange[1] > centerX) { if (lastRange[1] > centerX) {
// straddle, choose one or the other based on direction // straddle, choose one or the other based on direction
return new RXingResultPoint(lastRange[deltaY > 0 ? 0 : 1], lastY); return RXingResultPoint::new(
lastRange[if deltaY > 0 { 0 } else { 1 }],
lastY,
);
} }
return new RXingResultPoint(lastRange[0], lastY); return RXingResultPoint::new(lastRange[0], lastY);
} else { } else {
return new RXingResultPoint(lastRange[1], lastY); return RXingResultPoint::new(lastRange[1], lastY);
} }
} else { } else {
int lastX = x - deltaX; let lastX = x - deltaX;
if (lastRange[0] < centerY) { if (lastRange[0] < centerY) {
if (lastRange[1] > centerY) { if (lastRange[1] > centerY) {
return new RXingResultPoint(lastX, lastRange[deltaX < 0 ? 0 : 1]); return RXingResultPoint::new(
lastX,
lastRange[if deltaX < 0 { 0 } else { 1 }],
);
} }
return new RXingResultPoint(lastX, lastRange[0]); return RXingResultPoint::new(lastX, lastRange[0]);
} else { } else {
return new RXingResultPoint(lastX, lastRange[1]); return RXingResultPoint::new(lastX, lastRange[1]);
} }
} }
} }
lastRange = range; lastRange = range;
y += deltaY;
x += deltaX
} }
throw NotFoundException.getNotFoundInstance(); return Err(NotFoundException.getNotFoundInstance());
} }
/** /**
@@ -166,51 +224,79 @@ public final class MonochromeRectangleDetector {
* @return int[] with start and end of found range, or null if no such range is found * @return int[] with start and end of found range, or null if no such range is found
* (e.g. only white was found) * (e.g. only white was found)
*/ */
private int[] blackWhiteRange(int fixedDimension, int maxWhiteRun, int minDim, int maxDim, boolean horizontal) { fn blackWhiteRange(
fixedDimension: i32,
int center = (minDim + maxDim) / 2; maxWhiteRun: i32,
minDim: i32,
maxDim: i32,
horizontal: bool,
) -> Option<Vec<i32>> {
let center = (minDim + maxDim) / 2;
// Scan left/up first // Scan left/up first
int start = center; let start = center;
while (start >= minDim) { while (start >= minDim) {
if (horizontal ? image.get(start, fixedDimension) : image.get(fixedDimension, start)) { if (if horizontal {
start--; image.get(start, fixedDimension)
} else { } else {
int whiteRunStart = start; image.get(fixedDimension, start)
do { }) {
start--; start = start - 1;
} while (start >= minDim && !(horizontal ? image.get(start, fixedDimension) : } else {
image.get(fixedDimension, start))); let whiteRunStart = start;
int whiteRunSize = whiteRunStart - start; start = start - 1;
while start >= minDim
&& !(if horizontal {
image.get(start, fixedDimension);
} else {
image.get(fixedDimension, start);
})
{
start = start - 1;
}
let whiteRunSize = whiteRunStart - start;
if (start < minDim || whiteRunSize > maxWhiteRun) { if (start < minDim || whiteRunSize > maxWhiteRun) {
start = whiteRunStart; start = whiteRunStart;
break; break;
} }
} }
} }
start++; start = start + 1;
// Then try right/down // Then try right/down
int end = center; let end = center;
while (end < maxDim) { while (end < maxDim) {
if (horizontal ? image.get(end, fixedDimension) : image.get(fixedDimension, end)) { if (if horizontal {
end++; image.get(end, fixedDimension)
} else { } else {
int whiteRunStart = end; image.get(fixedDimension, end)
do { }) {
end++; end = end + 1;
} while (end < maxDim && !(horizontal ? image.get(end, fixedDimension) : } else {
image.get(fixedDimension, end))); let whiteRunStart = end;
int whiteRunSize = end - whiteRunStart; end = end + 1;
while end < maxDim
&& !(if horizontal {
image.get(end, fixedDimension)
} else {
image.get(fixedDimension, end)
})
{
end = end + 1;
}
let whiteRunSize = end - whiteRunStart;
if (end >= maxDim || whiteRunSize > maxWhiteRun) { if (end >= maxDim || whiteRunSize > maxWhiteRun) {
end = whiteRunStart; end = whiteRunStart;
break; break;
} }
} }
} }
end--; end = end - 1;
return end > start ? new int[]{start, end} : null; return if end > start {
Some(Vec! {start, end})
} else {
None
};
} }
} }

View File

@@ -14,11 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
package com.google.zxing.common.detector; //package com.google.zxing.common.detector;
import com.google.zxing.NotFoundException; use crate::{NotFoundException,RXingResultPoint};
import com.google.zxing.RXingResultPoint; use crate::common::BitMatrix;
import com.google.zxing.common.BitMatrix;
/** /**
* <p> * <p>
@@ -30,21 +29,23 @@ import com.google.zxing.common.BitMatrix;
* *
* @author David Olivier * @author David Olivier
*/ */
public final class WhiteRectangleDetector { const INIT_SIZE:i32 = 10;
const CORR:i32 = 1;
pub struct WhiteRectangleDetector {
private static final int INIT_SIZE = 10; image: BitMatrix,
private static final int CORR = 1; height: i32,
width: i32,
leftInit: i32,
rightInit: i32,
downInit: i32,
upInit: i32,
}
private final BitMatrix image; impl WhiteRectangleDetector {
private final int height;
private final int width;
private final int leftInit;
private final int rightInit;
private final int downInit;
private final int upInit;
public WhiteRectangleDetector(BitMatrix image) throws NotFoundException { pub fn new_from_image(image:&BitMatrix) -> Result<Self,NotFoundException> {
this(image, INIT_SIZE, image.getWidth() / 2, image.getHeight() / 2); Self::new(image, INIT_SIZE, image.getWidth() / 2, image.getHeight() / 2);
} }
/** /**
@@ -54,18 +55,21 @@ public final class WhiteRectangleDetector {
* @param y y position of search center * @param y y position of search center
* @throws NotFoundException if image is too small to accommodate {@code initSize} * @throws NotFoundException if image is too small to accommodate {@code initSize}
*/ */
public WhiteRectangleDetector(BitMatrix image, int initSize, int x, int y) throws NotFoundException { pub fn new( image:&BitMatrix, initSize:i32, x:i32, y:i32) -> Result<Self, NotFoundException> {
this.image = image; let new_wrd : Self;
height = image.getHeight(); new_wrd.image = image;
width = image.getWidth(); new_wrd.height = image.getHeight();
int halfsize = initSize / 2; new_wrd.width = image.getWidth();
leftInit = x - halfsize; let halfsize = initSize / 2;
rightInit = x + halfsize; new_wrd.leftInit = x - halfsize;
upInit = y - halfsize; new_wrd.rightInit = x + halfsize;
downInit = y + halfsize; new_wrd.upInit = y - halfsize;
new_wrd.downInit = y + halfsize;
if (upInit < 0 || leftInit < 0 || downInit >= height || rightInit >= width) { if (upInit < 0 || leftInit < 0 || downInit >= height || rightInit >= width) {
throw NotFoundException.getNotFoundInstance(); return Err( NotFoundException.getNotFoundInstance());
} }
Ok(new_wrd)
} }
/** /**
@@ -82,19 +86,19 @@ public final class WhiteRectangleDetector {
* leftmost and the third, the rightmost * leftmost and the third, the rightmost
* @throws NotFoundException if no Data Matrix Code can be found * @throws NotFoundException if no Data Matrix Code can be found
*/ */
public RXingResultPoint[] detect() throws NotFoundException { pub fn detect() -> Result<Vec<RXingResultPoint>, NotFoundException> {
int left = leftInit; let left :i32= leftInit;
int right = rightInit; let right:i32 = rightInit;
int up = upInit; let up:i32 = upInit;
int down = downInit; let down:i32 = downInit;
boolean sizeExceeded = false; let sizeExceeded = false;
boolean aBlackPointFoundOnBorder = true; let aBlackPointFoundOnBorder = true;
boolean atLeastOneBlackPointFoundOnRight = false; let atLeastOneBlackPointFoundOnRight = false;
boolean atLeastOneBlackPointFoundOnBottom = false; let atLeastOneBlackPointFoundOnBottom = false;
boolean atLeastOneBlackPointFoundOnLeft = false; let atLeastOneBlackPointFoundOnLeft = false;
boolean atLeastOneBlackPointFoundOnTop = false; let atLeastOneBlackPointFoundOnTop = false;
while (aBlackPointFoundOnBorder) { while (aBlackPointFoundOnBorder) {
@@ -103,15 +107,15 @@ public final class WhiteRectangleDetector {
// ..... // .....
// . | // . |
// ..... // .....
boolean rightBorderNotWhite = true; let rightBorderNotWhite = true;
while ((rightBorderNotWhite || !atLeastOneBlackPointFoundOnRight) && 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 += 1;
aBlackPointFoundOnBorder = true; aBlackPointFoundOnBorder = true;
atLeastOneBlackPointFoundOnRight = true; atLeastOneBlackPointFoundOnRight = true;
} else if (!atLeastOneBlackPointFoundOnRight) { } else if (!atLeastOneBlackPointFoundOnRight) {
right++; right+=1;
} }
} }
@@ -123,15 +127,15 @@ public final class WhiteRectangleDetector {
// ..... // .....
// . . // . .
// .___. // .___.
boolean bottomBorderNotWhite = true; let bottomBorderNotWhite = true;
while ((bottomBorderNotWhite || !atLeastOneBlackPointFoundOnBottom) && 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+=1;
aBlackPointFoundOnBorder = true; aBlackPointFoundOnBorder = true;
atLeastOneBlackPointFoundOnBottom = true; atLeastOneBlackPointFoundOnBottom = true;
} else if (!atLeastOneBlackPointFoundOnBottom) { } else if (!atLeastOneBlackPointFoundOnBottom) {
down++; down+=1;
} }
} }
@@ -143,15 +147,15 @@ public final class WhiteRectangleDetector {
// ..... // .....
// | . // | .
// ..... // .....
boolean leftBorderNotWhite = true; let leftBorderNotWhite = true;
while ((leftBorderNotWhite || !atLeastOneBlackPointFoundOnLeft) && 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-=1;
aBlackPointFoundOnBorder = true; aBlackPointFoundOnBorder = true;
atLeastOneBlackPointFoundOnLeft = true; atLeastOneBlackPointFoundOnLeft = true;
} else if (!atLeastOneBlackPointFoundOnLeft) { } else if (!atLeastOneBlackPointFoundOnLeft) {
left--; left-=1;
} }
} }
@@ -163,15 +167,15 @@ public final class WhiteRectangleDetector {
// .___. // .___.
// . . // . .
// ..... // .....
boolean topBorderNotWhite = true; let topBorderNotWhite = true;
while ((topBorderNotWhite || !atLeastOneBlackPointFoundOnTop) && 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-=1;
aBlackPointFoundOnBorder = true; aBlackPointFoundOnBorder = true;
atLeastOneBlackPointFoundOnTop = true; atLeastOneBlackPointFoundOnTop = true;
} else if (!atLeastOneBlackPointFoundOnTop) { } else if (!atLeastOneBlackPointFoundOnTop) {
up--; up-=1;
} }
} }
@@ -184,67 +188,79 @@ public final class WhiteRectangleDetector {
if (!sizeExceeded) { if (!sizeExceeded) {
int maxSize = right - left; let maxSize = right - left;
RXingResultPoint z = null; let mut z: Option<RXingResultPoint> = None;
for (int i = 1; z == null && i < maxSize; i++) { let mut i = 1;
while z.is_none() && i < maxSize {
//for (int i = 1; z == null && i < maxSize; i++) {
z = getBlackPointOnSegment(left, down - i, left + i, down); z = getBlackPointOnSegment(left, down - i, left + i, down);
i+=1;
} }
if (z == null) { if (z .is_none()) {
throw NotFoundException.getNotFoundInstance(); return Err( NotFoundException.getNotFoundInstance());
} }
RXingResultPoint t = null; let mut t : Option<RXingResultPoint> = None;
//go down right //go down right
for (int i = 1; t == null && i < maxSize; i++) { let mut i = 1;
while t.is_none() && i < maxSize {
//for (int i = 1; t == null && i < maxSize; i++) {
t = getBlackPointOnSegment(left, up + i, left + i, up); t = getBlackPointOnSegment(left, up + i, left + i, up);
i+=1;
} }
if (t == null) { if (t .is_none()) {
throw NotFoundException.getNotFoundInstance(); return Err( NotFoundException.getNotFoundInstance());
} }
RXingResultPoint x = null; let mut x : Option<RXingResultPoint> = None;
//go down left //go down left
for (int i = 1; x == null && i < maxSize; i++) { let mut i = 1;
while x.is_none() && i < maxSize {
//for (int i = 1; x == null && i < maxSize; i++) {
x = getBlackPointOnSegment(right, up + i, right - i, up); x = getBlackPointOnSegment(right, up + i, right - i, up);
i += 1;
} }
if (x == null) { if (x .is_none()) {
throw NotFoundException.getNotFoundInstance(); return Err( NotFoundException.getNotFoundInstance());
} }
RXingResultPoint y = null; let mut y : Option<RXingResultPoint> = None;
//go up left //go up left
for (int i = 1; y == null && i < maxSize; i++) { let mut i = 1;
while y.is_none() && i < maxSize {
//for (int i = 1; y == null && i < maxSize; i++) {
y = getBlackPointOnSegment(right, down - i, right - i, down); y = getBlackPointOnSegment(right, down - i, right - i, down);
i+=1;
} }
if (y == null) { if (y .is_none()) {
throw NotFoundException.getNotFoundInstance(); return Err( NotFoundException.getNotFoundInstance());
} }
return centerEdges(y, z, x, t); return centerEdges(y, z, x, t);
} else { } else {
throw NotFoundException.getNotFoundInstance(); return Err( NotFoundException.getNotFoundInstance());
} }
} }
private RXingResultPoint getBlackPointOnSegment(float aX, float aY, float bX, float bY) { fn getBlackPointOnSegment( aX:f32, aY:f32, bX:f32, bY:f32) -> Option<RXingResultPoint> {
int dist = MathUtils.round(MathUtils.distance(aX, aY, bX, bY)); let dist = MathUtils.round(MathUtils.distance(aX, aY, bX, bY));
float xStep = (bX - aX) / dist; let xStep :f32= (bX - aX) / dist;
float yStep = (bY - aY) / dist; let yStep:f32 = (bY - aY) / dist;
for (int i = 0; i < dist; i++) { for i in 0..dist {
int x = MathUtils.round(aX + i * xStep); let x = MathUtils.round(aX + i * xStep);
int y = MathUtils.round(aY + i * yStep); let y = MathUtils.round(aY + i * yStep);
if (image.get(x, y)) { if (image.get(x, y)) {
return new RXingResultPoint(x, y); return RXingResultPoint::new(x, y);
} }
} }
return null; return None;
} }
/** /**
@@ -260,8 +276,8 @@ public final class WhiteRectangleDetector {
* point and the last, the bottommost. The second point will be * point and the last, the bottommost. The second point will be
* leftmost and the third, the rightmost * leftmost and the third, the rightmost
*/ */
private RXingResultPoint[] centerEdges(RXingResultPoint y, RXingResultPoint z, fn centerEdges( y:&RXingResultPoint, z:&RXingResultPoint,
RXingResultPoint x, RXingResultPoint t) { x:&RXingResultPoint, t:&RXingResultPoint) -> Vec<RXingResultPoint> {
// //
// t t // t t
@@ -270,27 +286,27 @@ public final class WhiteRectangleDetector {
// y y // y y
// //
float yi = y.getX(); let yi = y.getX();
float yj = y.getY(); let yj = y.getY();
float zi = z.getX(); let zi = z.getX();
float zj = z.getY(); let zj = z.getY();
float xi = x.getX(); let xi = x.getX();
float xj = x.getY(); let xj = x.getY();
float ti = t.getX(); let ti = t.getX();
float tj = t.getY(); let tj = t.getY();
if (yi < width / 2.0f) { if (yi < width / 2.0f) {
return new RXingResultPoint[]{ return Vec!
new RXingResultPoint(ti - CORR, tj + CORR), [ RXingResultPoint::new(ti - CORR, tj + CORR),
new RXingResultPoint(zi + CORR, zj + CORR), RXingResultPoint::new(zi + CORR, zj + CORR),
new RXingResultPoint(xi - CORR, xj - CORR), RXingResultPoint::new(xi - CORR, xj - CORR),
new RXingResultPoint(yi + CORR, yj - CORR)}; RXingResultPoint::new(yi + CORR, yj - CORR)];
} else { } else {
return new RXingResultPoint[]{ return Vec![
new RXingResultPoint(ti + CORR, tj + CORR), RXingResultPoint::new(ti + CORR, tj + CORR),
new RXingResultPoint(zi + CORR, zj - CORR), RXingResultPoint::new(zi + CORR, zj - CORR),
new RXingResultPoint(xi - CORR, xj + CORR), RXingResultPoint::new(xi - CORR, xj + CORR),
new RXingResultPoint(yi - CORR, yj - CORR)}; RXingResultPoint::new(yi - CORR, yj - CORR)];
} }
} }
@@ -303,16 +319,18 @@ public final class WhiteRectangleDetector {
* @param horizontal set to true if scan must be horizontal, false if vertical * @param horizontal set to true if scan must be horizontal, false if vertical
* @return true if a black point has been found, else false. * @return true if a black point has been found, else false.
*/ */
private boolean containsBlackPoint(int a, int b, int fixed, boolean horizontal) { fn containsBlackPoint( a:i32, b:i32, fixed:i32, horizontal:bool) -> bool {
if (horizontal) { if (horizontal) {
for (int x = a; x <= b; x++) {
for x in a..=b {
if (image.get(x, fixed)) { if (image.get(x, fixed)) {
return true; return true;
} }
} }
} else { } else {
for (int y = a; y <= b; y++) {
for y in a..=b {
if (image.get(fixed, y)) { if (image.get(fixed, y)) {
return true; return true;
} }