/** * <p>Determines if this finder pattern "about equals" a finder pattern at the stated * position and size -- meaning, it is at nearly the same center with nearly the same size.</p> */ boolean aboutEquals(float moduleSize, float i, float j) { if (Math.abs(i - getY()) <= moduleSize && Math.abs(j - getX()) <= moduleSize) { float moduleSizeDiff = Math.abs(moduleSize - estimatedModuleSize); return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize; } return false; }
/** * <p>Determines if this finder pattern "about equals" a finder pattern at the stated * position and size -- meaning, it is at nearly the same center with nearly the same size.</p> */ boolean aboutEquals(float moduleSize, float i, float j) { if (Math.abs(i - getY()) <= moduleSize && Math.abs(j - getX()) <= moduleSize) { float moduleSizeDiff = Math.abs(moduleSize - estimatedModuleSize); return moduleSizeDiff <= 1.0f || moduleSizeDiff / estimatedModuleSize <= 1.0f; } return false; }
/** * <p>Determines if this finder pattern "about equals" a finder pattern at the stated * position and size -- meaning, it is at nearly the same center with nearly the same size.</p> */ boolean aboutEquals(float moduleSize, float i, float j) { if (Math.abs(i - getY()) <= moduleSize && Math.abs(j - getX()) <= moduleSize) { float moduleSizeDiff = Math.abs(moduleSize - estimatedModuleSize); return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize; } return false; }
/** * Combines this object's current estimate of a finder pattern position and module size * with a new estimate. It returns a new {@code FinderPattern} containing a weighted average * based on count. */ FinderPattern combineEstimate(float i, float j, float newModuleSize) { int combinedCount = count + 1; float combinedX = (count * getX() + j) / combinedCount; float combinedY = (count * getY() + i) / combinedCount; float combinedModuleSize = (count * estimatedModuleSize + newModuleSize) / combinedCount; return new FinderPattern(combinedX, combinedY, combinedModuleSize, combinedCount); }
/** * Combines this object's current estimate of a finder pattern position and module size * with a new estimate. It returns a new {@code FinderPattern} containing a weighted average * based on count. */ FinderPattern combineEstimate(float i, float j, float newModuleSize) { int combinedCount = count + 1; float combinedX = (count * getX() + j) / combinedCount; float combinedY = (count * getY() + i) / combinedCount; float combinedModuleSize = (count * estimatedModuleSize + newModuleSize) / combinedCount; return new FinderPattern(combinedX, combinedY, combinedModuleSize, combinedCount); }
/** * @return number of rows we could safely skip during scanning, based on the first * two finder patterns that have been located. In some cases their position will * allow us to infer that the third pattern must lie below a certain point farther * down in the image. */ private int findRowSkip() { int max = possibleCenters.size(); if (max <= 1) { return 0; } ResultPoint firstConfirmedCenter = null; for (FinderPattern center : possibleCenters) { if (center.getCount() >= CENTER_QUORUM) { if (firstConfirmedCenter == null) { firstConfirmedCenter = center; } else { // We have two confirmed centers // How far down can we skip before resuming looking for the next // pattern? In the worst case, only the difference between the // difference in the x / y coordinates of the two centers. // This is the case where you find top left last. hasSkipped = true; return (int) (Math.abs(firstConfirmedCenter.getX() - center.getX()) - Math.abs(firstConfirmedCenter.getY() - center.getY())) / 2; } } } return 0; }
/** * @return number of rows we could safely skip during scanning, based on the first * two finder patterns that have been located. In some cases their position will * allow us to infer that the third pattern must lie below a certain point farther * down in the image. */ private int findRowSkip() { int max = possibleCenters.size(); if (max <= 1) { return 0; } ResultPoint firstConfirmedCenter = null; for (FinderPattern center : possibleCenters) { if (center.getCount() >= CENTER_QUORUM) { if (firstConfirmedCenter == null) { firstConfirmedCenter = center; } else { // We have two confirmed centers // How far down can we skip before resuming looking for the next // pattern? In the worst case, only the difference between the // difference in the x / y coordinates of the two centers. // This is the case where you find top left last. hasSkipped = true; return (int) (Math.abs(firstConfirmedCenter.getX() - center.getX()) - Math.abs(firstConfirmedCenter.getY() - center.getY())) / 2; } } } return 0; }
float bottomRightX = topRight.getX() - topLeft.getX() + bottomLeft.getX(); float bottomRightY = topRight.getY() - topLeft.getY() + bottomLeft.getY(); int estAlignmentX = (int) (topLeft.getX() + correctionToTopLeft * (bottomRightX - topLeft.getX())); int estAlignmentY = (int) (topLeft.getY() + correctionToTopLeft * (bottomRightY - topLeft.getY()));
float bottomRightX = topRight.getX() - topLeft.getX() + bottomLeft.getX(); float bottomRightY = topRight.getY() - topLeft.getY() + bottomLeft.getY(); int estAlignmentX = (int) (topLeft.getX() + correctionToTopLeft * (bottomRightX - topLeft.getX())); int estAlignmentY = (int) (topLeft.getY() + correctionToTopLeft * (bottomRightY - topLeft.getY()));
float bottomRightX = topRight.getX() - topLeft.getX() + bottomLeft.getX(); float bottomRightY = topRight.getY() - topLeft.getY() + bottomLeft.getY(); int estAlignmentX = (int) (topLeft.getX() + correctionToTopLeft * (bottomRightX - topLeft.getX())); int estAlignmentY = (int) (topLeft.getY() + correctionToTopLeft * (bottomRightY - topLeft.getY()));