Detector.java revision 7e3fa36d69ffee874dd364b8e3d9aa3cab9a273b
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* <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>
*
* @author Sean Owen
*/
public class Detector {
private ResultPointCallback resultPointCallback;
}
return image;
}
protected final ResultPointCallback getResultPointCallback() {
return resultPointCallback;
}
/**
* <p>Detects a QR Code in an image, simply.</p>
*
* @return {@link DetectorResult} encapsulating results of detecting a QR Code
* @throws NotFoundException if no QR Code can be found
*/
}
/**
* <p>Detects a QR Code in an image, simply.</p>
*
* @param hints optional hints to detector
* @return {@link NotFoundException} encapsulating results of detecting a QR Code
* @throws NotFoundException if QR Code cannot be found
* @throws FormatException if a QR Code cannot be decoded
*/
public final DetectorResult detect(Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
return processFinderPatternInfo(info);
}
throws NotFoundException, FormatException {
if (moduleSize < 1.0f) {
throw NotFoundException.getNotFoundInstance();
}
// Anything above version 1 has an alignment pattern
// Guess where a "bottom right" finder pattern would have been
// Estimate that alignment pattern is closer by 3 modules
// from "bottom right" to known top left location
// Kind of arbitrary -- expand search radius before giving up
for (int i = 4; i <= 16; i <<= 1) {
try {
(float) i);
break;
} catch (NotFoundException re) {
// try next round
}
}
// If we didn't find alignment pattern... well try anyway without it
}
if (alignmentPattern == null) {
} else {
}
}
int dimension) {
float bottomRightX;
float bottomRightY;
float sourceBottomRightX;
float sourceBottomRightY;
if (alignmentPattern != null) {
} else {
// Don't have an alignment pattern, just make up the bottom-right point
}
3.5f,
3.5f,
3.5f,
3.5f,
bottomLeft.getX(),
bottomLeft.getY());
}
int dimension) throws NotFoundException {
}
/**
* <p>Computes the dimension (number of modules on a size) of the QR Code based on the position
* of the finder patterns and estimated module size.</p>
*/
float moduleSize) throws NotFoundException {
case 0:
dimension++;
break;
// 1? do nothing
case 2:
dimension--;
break;
case 3:
throw NotFoundException.getNotFoundInstance();
}
return dimension;
}
/**
* <p>Computes an average estimated module size based on estimated derived from the positions
* of the three finder patterns.</p>
*/
// Take the average
}
/**
* <p>Estimates module size based on two finder patterns -- it uses
* {@link #sizeOfBlackWhiteBlackRunBothWays(int, int, int, int)} to figure the
* width of each, measuring along the axis between their centers.</p>
*/
(int) otherPattern.getX(),
(int) otherPattern.getY());
(int) otherPattern.getY(),
return moduleSizeEst2 / 7.0f;
}
return moduleSizeEst1 / 7.0f;
}
// Average them, and divide by 7 since we've counted the width of 3 black modules,
// and 1 white and 1 black module on either side. Ergo, divide sum by 14.
}
/**
* See {@link #sizeOfBlackWhiteBlackRun(int, int, int, int)}; computes the total width of
* 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>
*/
// Now count other way -- don't run off image though of course
float scale = 1.0f;
if (otherToX < 0) {
otherToX = 0;
}
scale = 1.0f;
if (otherToY < 0) {
otherToY = 0;
}
// Middle pixel is double-counted this way; subtract 1
return result - 1.0f;
}
/**
* <p>This method traces a line from a point in the image, in the direction towards another point.
* It begins in a black region, and keeps going until it finds white, then black, then white again.
* It reports the distance from the start to this point.</p>
*
* <p>This is used when figuring out how wide a finder pattern is, when the finder pattern
* may be skewed or rotated.</p>
*/
// Mild variant of Bresenham's algorithm;
// see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
if (steep) {
}
// In black pixels, looking for white, first or second time.
int state = 0;
// Loop up until x == toX, but not beyond
// Does current pixel mean we have moved white to black or vice versa?
// Scanning black in state 0,2 and white in state 1, so if we find the wrong
// color, advance to next state or end if we are in state 2 already
if (state == 2) {
}
state++;
}
if (error > 0) {
if (y == toY) {
break;
}
y += ystep;
}
}
// Found black-white-black; give the benefit of the doubt that the next pixel outside the image
// is "white" so this last point at (toX+xStep,toY) is the right ending. This is really a
// small approximation; (toX+xStep,toY+yStep) might be really correct. Ignore this.
if (state == 2) {
}
// else we didn't find even black-white-black; no estimate is really possible
}
/**
* <p>Attempts to locate an alignment pattern in a limited region of the image, which is
* guessed to contain it. This method uses {@link AlignmentPattern}.</p>
*
* @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 directions to search from the center
* @return {@link AlignmentPattern} if found, or null otherwise
* @throws NotFoundException if an unexpected error occurs during detection
*/
int estAlignmentX,
int estAlignmentY,
float allowanceFactor)
throws NotFoundException {
// Look for an alignment pattern (3 modules in size) around where it
// should be
throw NotFoundException.getNotFoundInstance();
}
throw NotFoundException.getNotFoundInstance();
}
return alignmentFinder.find();
}
}