tweak formating

git-svn-id: https://zxing.googlecode.com/svn/trunk@2489 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
smparkes@smparkes.net 2012-10-29 22:33:26 +00:00
parent 1cb7380961
commit 7a82d685a3

View file

@ -33,31 +33,38 @@
namespace math_utils = zxing::common::detector::math_utils; namespace math_utils = zxing::common::detector::math_utils;
namespace zxing { using std::ostringstream;
namespace qrcode { using std::min;
using std::max;
using std::isnan;
using zxing::qrcode::Detector;
using zxing::Ref;
using zxing::BitMatrix;
using zxing::ResultPointCallback;
using zxing::DetectorResult;
using zxing::PerspectiveTransform;
using zxing::qrcode::AlignmentPattern;
using namespace std; Detector::Detector(Ref<BitMatrix> image) :
Detector::Detector(Ref<BitMatrix> image) :
image_(image) { image_(image) {
} }
Ref<BitMatrix> Detector::getImage() const { Ref<BitMatrix> Detector::getImage() const {
return image_; return image_;
} }
Ref<ResultPointCallback> Detector::getResultPointCallback() const { Ref<ResultPointCallback> Detector::getResultPointCallback() const {
return callback_; return callback_;
} }
Ref<DetectorResult> Detector::detect(DecodeHints const& hints) { Ref<DetectorResult> Detector::detect(DecodeHints const& hints) {
callback_ = hints.getResultPointCallback(); callback_ = hints.getResultPointCallback();
FinderPatternFinder finder(image_, hints.getResultPointCallback()); FinderPatternFinder finder(image_, hints.getResultPointCallback());
Ref<FinderPatternInfo> info(finder.find(hints)); Ref<FinderPatternInfo> info(finder.find(hints));
return processFinderPatternInfo(info); return processFinderPatternInfo(info);
} }
Ref<DetectorResult> Detector::processFinderPatternInfo(Ref<FinderPatternInfo> info){ Ref<DetectorResult> Detector::processFinderPatternInfo(Ref<FinderPatternInfo> info){
Ref<FinderPattern> topLeft(info->getTopLeft()); Ref<FinderPattern> topLeft(info->getTopLeft());
Ref<FinderPattern> topRight(info->getTopRight()); Ref<FinderPattern> topRight(info->getTopRight());
Ref<FinderPattern> bottomLeft(info->getBottomLeft()); Ref<FinderPattern> bottomLeft(info->getBottomLeft());
@ -114,9 +121,9 @@ namespace zxing {
Ref<DetectorResult> result(new DetectorResult(bits, points)); Ref<DetectorResult> result(new DetectorResult(bits, points));
return result; return result;
} }
Ref<PerspectiveTransform> Detector::createTransform(Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight, Ref < Ref<PerspectiveTransform> Detector::createTransform(Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight, Ref <
ResultPoint > bottomLeft, Ref<ResultPoint> alignmentPattern, int dimension) { ResultPoint > bottomLeft, Ref<ResultPoint> alignmentPattern, int dimension) {
float dimMinusThree = (float)dimension - 3.5f; float dimMinusThree = (float)dimension - 3.5f;
@ -142,14 +149,14 @@ namespace zxing {
topRight->getY(), bottomRightX, bottomRightY, bottomLeft->getX(), bottomLeft->getY())); topRight->getY(), bottomRightX, bottomRightY, bottomLeft->getX(), bottomLeft->getY()));
return transform; return transform;
} }
Ref<BitMatrix> Detector::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<PerspectiveTransform> transform) { Ref<BitMatrix> Detector::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<PerspectiveTransform> transform) {
GridSampler &sampler = GridSampler::getInstance(); GridSampler &sampler = GridSampler::getInstance();
return sampler.sampleGrid(image, dimension, transform); return sampler.sampleGrid(image, dimension, transform);
} }
int Detector::computeDimension(Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight, Ref<ResultPoint> bottomLeft, int Detector::computeDimension(Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight, Ref<ResultPoint> bottomLeft,
float moduleSize) { float moduleSize) {
int tltrCentersDimension = int tltrCentersDimension =
math_utils::round(ResultPoint::distance(topLeft, topRight) / moduleSize); math_utils::round(ResultPoint::distance(topLeft, topRight) / moduleSize);
@ -170,14 +177,14 @@ namespace zxing {
throw zxing::ReaderException(s.str().c_str()); throw zxing::ReaderException(s.str().c_str());
} }
return dimension; return dimension;
} }
float Detector::calculateModuleSize(Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight, Ref<ResultPoint> bottomLeft) { float Detector::calculateModuleSize(Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight, Ref<ResultPoint> bottomLeft) {
// Take the average // Take the average
return (calculateModuleSizeOneWay(topLeft, topRight) + calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0f; return (calculateModuleSizeOneWay(topLeft, topRight) + calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0f;
} }
float Detector::calculateModuleSizeOneWay(Ref<ResultPoint> pattern, Ref<ResultPoint> otherPattern) { float Detector::calculateModuleSizeOneWay(Ref<ResultPoint> pattern, Ref<ResultPoint> otherPattern) {
float moduleSizeEst1 = sizeOfBlackWhiteBlackRunBothWays((int)pattern->getX(), (int)pattern->getY(), float moduleSizeEst1 = sizeOfBlackWhiteBlackRunBothWays((int)pattern->getX(), (int)pattern->getY(),
(int)otherPattern->getX(), (int)otherPattern->getY()); (int)otherPattern->getX(), (int)otherPattern->getY());
float moduleSizeEst2 = sizeOfBlackWhiteBlackRunBothWays((int)otherPattern->getX(), (int)otherPattern->getY(), float moduleSizeEst2 = sizeOfBlackWhiteBlackRunBothWays((int)otherPattern->getX(), (int)otherPattern->getY(),
@ -191,9 +198,9 @@ namespace zxing {
// Average them, and divide by 7 since we've counted the width of 3 black modules, // 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. // and 1 white and 1 black module on either side. Ergo, divide sum by 14.
return (moduleSizeEst1 + moduleSizeEst2) / 14.0f; return (moduleSizeEst1 + moduleSizeEst2) / 14.0f;
} }
float Detector::sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, int toY) { float Detector::sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, int toY) {
float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY); float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);
@ -223,9 +230,9 @@ namespace zxing {
// Middle pixel is double-counted this way; subtract 1 // Middle pixel is double-counted this way; subtract 1
return result - 1.0f; return result - 1.0f;
} }
float Detector::sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY) { float Detector::sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY) {
// Mild variant of Bresenham's algorithm; // Mild variant of Bresenham's algorithm;
// see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm // see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
bool steep = abs(toY - fromY) > abs(toX - fromX); bool steep = abs(toY - fromY) > abs(toX - fromX);
@ -277,9 +284,9 @@ namespace zxing {
} }
// else we didn't find even black-white-black; no estimate is really possible // else we didn't find even black-white-black; no estimate is really possible
return NAN; return NAN;
} }
Ref<AlignmentPattern> Detector::findAlignmentInRegion(float overallEstModuleSize, int estAlignmentX, int estAlignmentY, Ref<AlignmentPattern> Detector::findAlignmentInRegion(float overallEstModuleSize, int estAlignmentX, int estAlignmentY,
float allowanceFactor) { float allowanceFactor) {
// Look for an alignment pattern (3 modules in size) around where it // Look for an alignment pattern (3 modules in size) around where it
// should be // should be
@ -298,7 +305,4 @@ namespace zxing {
AlignmentPatternFinder alignmentFinder(image_, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX AlignmentPatternFinder alignmentFinder(image_, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX
- alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, callback_); - alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, callback_);
return alignmentFinder.find(); return alignmentFinder.find();
}
}
} }