Take small advantage of "TRY_HARDER" in QR code decoder

git-svn-id: https://zxing.googlecode.com/svn/trunk@299 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2008-03-19 17:10:58 +00:00
parent c28040bc61
commit fc2f28080d
3 changed files with 20 additions and 4 deletions

View file

@ -61,7 +61,7 @@ public final class QRCodeReader implements Reader {
decoderResult = decoder.decode(bits);
points = NO_POINTS;
} else {
DetectorResult result = new Detector(image).detect();
DetectorResult result = new Detector(image).detect(hints);
decoderResult = decoder.decode(result.getBits());
points = result.getPoints();
}

View file

@ -25,6 +25,8 @@ import com.google.zxing.common.DetectorResult;
import com.google.zxing.common.GridSampler;
import com.google.zxing.qrcode.decoder.Version;
import java.util.Hashtable;
/**
* <p>Encapsulates logic that can detect a QR Code in an image, even if the QR Code
* is rotated or skewed, or partially obscured.</p>
@ -46,6 +48,17 @@ public final class Detector {
* @throws ReaderException if no QR Code can be found
*/
public DetectorResult detect() throws ReaderException {
return detect(null);
}
/**
* <p>Detects a QR Code in an image, simply.</p>
*
* @param hints optional hints to detector
* @return {@link DetectorResult} encapsulating results of detecting a QR Code
* @throws ReaderException if no QR Code can be found
*/
public DetectorResult detect(Hashtable hints) throws ReaderException {
MonochromeBitmapSource image = this.image;
if (!BlackPointEstimationMethod.TWO_D_SAMPLING.equals(image.getLastEstimationMethod())) {
@ -53,7 +66,7 @@ public final class Detector {
}
FinderPatternFinder finder = new FinderPatternFinder(image);
FinderPatternInfo info = finder.find();
FinderPatternInfo info = finder.find(hints);
FinderPattern topLeft = info.getTopLeft();
FinderPattern topRight = info.getTopRight();

View file

@ -16,6 +16,7 @@
package com.google.zxing.qrcode.detector;
import com.google.zxing.DecodeHintType;
import com.google.zxing.MonochromeBitmapSource;
import com.google.zxing.ReaderException;
import com.google.zxing.ResultPoint;
@ -23,6 +24,7 @@ import com.google.zxing.common.BitArray;
import com.google.zxing.common.Collections;
import com.google.zxing.common.Comparator;
import java.util.Hashtable;
import java.util.Vector;
/**
@ -52,7 +54,8 @@ final class FinderPatternFinder {
this.possibleCenters = new Vector();
}
FinderPatternInfo find() throws ReaderException {
FinderPatternInfo find(Hashtable hints) throws ReaderException {
boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
int maxI = image.getHeight();
int maxJ = image.getWidth();
// We are looking for black/white/black/white/black modules in
@ -61,7 +64,7 @@ final class FinderPatternFinder {
boolean done = false;
// We can afford to examine every few lines until we've started finding
// the patterns
int iSkip = BIG_SKIP;
int iSkip = tryHarder ? 1 : BIG_SKIP;
for (int i = iSkip - 1; i < maxI && !done; i += iSkip) {
// Get a row of black/white values
BitArray blackRow = image.getBlackRow(i, null, 0, maxJ);