Add hint to correct wrong dimension

Fix issue #1900
This commit is contained in:
Matthias Agethle 2025-02-03 11:17:02 +01:00
parent 2dfb2054af
commit 16723b3434
3 changed files with 25 additions and 6 deletions

View file

@ -104,6 +104,19 @@ public enum DecodeHintType {
*/
ALSO_INVERTED(Void.class),
/**
* If true, it will round down wrong dimension to next possible value.
* Doesn't matter what it maps to; use {@link Boolean#TRUE}.
*/
CORRECT_DIMENSION_TO_LOWER_VALUE(Void.class),
/**
* If true, it will round up wrong dimension to next possible value.
* Doesn't matter what it maps to; use {@link Boolean#TRUE}.
*/
CORRECT_DIMENSION_TO_UPPER_VALUE(Void.class),
// End of enumeration values.
;

View file

@ -58,7 +58,7 @@ public final class MultiDetector extends Detector {
List<DetectorResult> result = new ArrayList<>();
for (FinderPatternInfo info : infos) {
try {
result.add(processFinderPatternInfo(info));
result.add(processFinderPatternInfo(info, hints));
} catch (ReaderException e) {
// ignore
}

View file

@ -80,10 +80,10 @@ public class Detector {
FinderPatternFinder finder = new FinderPatternFinder(image, resultPointCallback);
FinderPatternInfo info = finder.find(hints);
return processFinderPatternInfo(info);
return processFinderPatternInfo(info, hints);
}
protected final DetectorResult processFinderPatternInfo(FinderPatternInfo info)
protected final DetectorResult processFinderPatternInfo(FinderPatternInfo info, Map<DecodeHintType,?> hints)
throws NotFoundException, FormatException {
FinderPattern topLeft = info.getTopLeft();
@ -94,7 +94,7 @@ public class Detector {
if (moduleSize < 1.0f) {
throw NotFoundException.getNotFoundInstance();
}
int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize);
int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize, hints);
Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension);
int modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7;
@ -198,7 +198,8 @@ public class Detector {
private static int computeDimension(ResultPoint topLeft,
ResultPoint topRight,
ResultPoint bottomLeft,
float moduleSize) throws NotFoundException {
float moduleSize,
Map<DecodeHintType,?> hints) throws NotFoundException {
int tltrCentersDimension = MathUtils.round(ResultPoint.distance(topLeft, topRight) / moduleSize);
int tlblCentersDimension = MathUtils.round(ResultPoint.distance(topLeft, bottomLeft) / moduleSize);
int dimension = ((tltrCentersDimension + tlblCentersDimension) / 2) + 7;
@ -211,7 +212,12 @@ public class Detector {
dimension--;
break;
case 3:
throw NotFoundException.getNotFoundInstance();
if (hints != null && hints.get(DecodeHintType.CORRECT_DIMENSION_TO_LOWER_VALUE)!=null)
dimension = dimension - 2;
else if (hints != null && hints.get(DecodeHintType.CORRECT_DIMENSION_TO_UPPER_VALUE)!=null)
dimension = dimension + 2;
else
throw NotFoundException.getNotFoundInstance();
}
return dimension;
}