package com.google.zxing.qrcode.detector;
-import com.google.zxing.BlackPointEstimationMethod;
-import com.google.zxing.MonochromeBitmapSource;
import com.google.zxing.ReaderException;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitMatrix;
*
* @author Sean Owen
*/
-public final class Detector {
+public class Detector {
- private final MonochromeBitmapSource image;
+ private final BitMatrix image;
- public Detector(MonochromeBitmapSource image) {
+ public Detector(BitMatrix image) {
this.image = image;
}
+ protected BitMatrix getImage() {
+ return image;
+ }
+
/**
* <p>Detects a QR Code in an image, simply.</p>
*
*/
public DetectorResult detect(Hashtable hints) throws ReaderException {
- MonochromeBitmapSource image = this.image;
- if (!BlackPointEstimationMethod.TWO_D_SAMPLING.equals(image.getLastEstimationMethod())) {
- image.estimateBlackPoint(BlackPointEstimationMethod.TWO_D_SAMPLING, 0);
- }
-
FinderPatternFinder finder = new FinderPatternFinder(image);
FinderPatternInfo info = finder.find(hints);
+ return processFinderPatternInfo(info);
+ }
+
+ protected DetectorResult processFinderPatternInfo(FinderPatternInfo info) throws ReaderException {
+
FinderPattern topLeft = info.getTopLeft();
FinderPattern topRight = info.getTopRight();
FinderPattern bottomLeft = info.getBottomLeft();
// try next round
}
}
- if (alignmentPattern == null) {
- throw ReaderException.getInstance();
- }
-
+ // If we didn't find alignment pattern... well try anyway without it
}
BitMatrix bits = sampleGrid(image, topLeft, topRight, bottomLeft, alignmentPattern, dimension);
return new DetectorResult(bits, points);
}
- private static BitMatrix sampleGrid(MonochromeBitmapSource image,
+ private static BitMatrix sampleGrid(BitMatrix image,
ResultPoint topLeft,
ResultPoint topRight,
ResultPoint bottomLeft,
* <p>Computes an average estimated module size based on estimated derived from the positions
* of the three finder patterns.</p>
*/
- private float calculateModuleSize(ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft) {
+ private float calculateModuleSize(ResultPoint topLeft, ResultPoint topRight,
+ ResultPoint bottomLeft) {
// Take the average
return (calculateModuleSizeOneWay(topLeft, topRight) +
calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0f;
int realX = steep ? y : x;
int realY = steep ? x : y;
if (state == 1) { // In white pixels, looking for black
- if (image.isBlack(realX, realY)) {
+ if (image.get(realX, realY)) {
state++;
}
} else {
- if (!image.isBlack(realX, realY)) {
+ if (!image.get(realX, realY)) {
state++;
}
}
* @param overallEstModuleSize estimated module size so far
* @param estAlignmentX x coordinate of center of area probably containing alignment pattern
* @param estAlignmentY y coordinate of above
- * @param allowanceFactor number of pixels in all directons to search from the center
+ * @param allowanceFactor number of pixels in all directions to search from the center
* @return {@link AlignmentPattern} if found, or null otherwise
* @throws ReaderException if an unexpected error occurs during detection
*/