import com.google.zxing.ReaderException;
import com.google.zxing.ResultPoint;
-import com.google.zxing.BinaryBitmap;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.DetectorResult;
import com.google.zxing.common.GridSampler;
*/
public class Detector {
- private final BinaryBitmap image;
+ private final BitMatrix image;
- public Detector(BinaryBitmap image) {
+ public Detector(BitMatrix image) {
this.image = image;
}
- protected BinaryBitmap getImage() {
+ protected BitMatrix getImage() {
return image;
}
*/
public DetectorResult detect(Hashtable hints) throws ReaderException {
- BinaryBitmap image = this.image;
FinderPatternFinder finder = new FinderPatternFinder(image);
FinderPatternInfo info = finder.find(hints);
return new DetectorResult(bits, points);
}
- private static BitMatrix sampleGrid(BinaryBitmap image,
+ private static BitMatrix sampleGrid(BitMatrix image,
ResultPoint topLeft,
ResultPoint topRight,
ResultPoint bottomLeft,
* of the three finder patterns.</p>
*/
private float calculateModuleSize(ResultPoint topLeft, ResultPoint topRight,
- ResultPoint bottomLeft) throws ReaderException {
+ ResultPoint bottomLeft) {
// Take the average
return (calculateModuleSizeOneWay(topLeft, topRight) +
calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0f;
* {@link #sizeOfBlackWhiteBlackRunBothWays(int, int, int, int)} to figure the
* width of each, measuring along the axis between their centers.</p>
*/
- private float calculateModuleSizeOneWay(ResultPoint pattern, ResultPoint otherPattern)
- throws ReaderException {
+ private float calculateModuleSizeOneWay(ResultPoint pattern, ResultPoint otherPattern) {
float moduleSizeEst1 = sizeOfBlackWhiteBlackRunBothWays((int) pattern.getX(),
(int) pattern.getY(),
(int) otherPattern.getX(),
* a finder pattern by looking for a black-white-black run from the center in the direction
* of another point (another finder pattern center), and in the opposite direction too.</p>
*/
- private float sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, int toY)
- throws ReaderException {
+ private float sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, int toY) {
float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);
* <p>This is used when figuring out how wide a finder pattern is, when the finder pattern
* may be skewed or rotated.</p>
*/
- private float sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY)
- throws ReaderException {
+ private float sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY) {
// Mild variant of Bresenham's algorithm;
// see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
boolean steep = Math.abs(toY - fromY) > Math.abs(toX - fromX);
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
*/