mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
tweak formating
git-svn-id: https://zxing.googlecode.com/svn/trunk@2489 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
1cb7380961
commit
7a82d685a3
|
@ -33,31 +33,38 @@
|
|||
|
||||
namespace math_utils = zxing::common::detector::math_utils;
|
||||
|
||||
namespace zxing {
|
||||
namespace qrcode {
|
||||
using std::ostringstream;
|
||||
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) {
|
||||
}
|
||||
}
|
||||
|
||||
Ref<BitMatrix> Detector::getImage() const {
|
||||
Ref<BitMatrix> Detector::getImage() const {
|
||||
return image_;
|
||||
}
|
||||
}
|
||||
|
||||
Ref<ResultPointCallback> Detector::getResultPointCallback() const {
|
||||
Ref<ResultPointCallback> Detector::getResultPointCallback() const {
|
||||
return callback_;
|
||||
}
|
||||
}
|
||||
|
||||
Ref<DetectorResult> Detector::detect(DecodeHints const& hints) {
|
||||
Ref<DetectorResult> Detector::detect(DecodeHints const& hints) {
|
||||
callback_ = hints.getResultPointCallback();
|
||||
FinderPatternFinder finder(image_, hints.getResultPointCallback());
|
||||
Ref<FinderPatternInfo> info(finder.find(hints));
|
||||
return processFinderPatternInfo(info);
|
||||
}
|
||||
}
|
||||
|
||||
Ref<DetectorResult> Detector::processFinderPatternInfo(Ref<FinderPatternInfo> info){
|
||||
Ref<DetectorResult> Detector::processFinderPatternInfo(Ref<FinderPatternInfo> info){
|
||||
Ref<FinderPattern> topLeft(info->getTopLeft());
|
||||
Ref<FinderPattern> topRight(info->getTopRight());
|
||||
Ref<FinderPattern> bottomLeft(info->getBottomLeft());
|
||||
|
@ -114,9 +121,9 @@ namespace zxing {
|
|||
|
||||
Ref<DetectorResult> result(new DetectorResult(bits, points));
|
||||
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) {
|
||||
|
||||
float dimMinusThree = (float)dimension - 3.5f;
|
||||
|
@ -142,14 +149,14 @@ namespace zxing {
|
|||
topRight->getY(), bottomRightX, bottomRightY, bottomLeft->getX(), bottomLeft->getY()));
|
||||
|
||||
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();
|
||||
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) {
|
||||
int tltrCentersDimension =
|
||||
math_utils::round(ResultPoint::distance(topLeft, topRight) / moduleSize);
|
||||
|
@ -170,14 +177,14 @@ namespace zxing {
|
|||
throw zxing::ReaderException(s.str().c_str());
|
||||
}
|
||||
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
|
||||
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(),
|
||||
(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,
|
||||
// and 1 white and 1 black module on either side. Ergo, divide sum by 14.
|
||||
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);
|
||||
|
||||
|
@ -223,9 +230,9 @@ namespace zxing {
|
|||
|
||||
// Middle pixel is double-counted this way; subtract 1
|
||||
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;
|
||||
// see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
|
||||
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
|
||||
return NAN;
|
||||
}
|
||||
}
|
||||
|
||||
Ref<AlignmentPattern> Detector::findAlignmentInRegion(float overallEstModuleSize, int estAlignmentX, int estAlignmentY,
|
||||
Ref<AlignmentPattern> Detector::findAlignmentInRegion(float overallEstModuleSize, int estAlignmentX, int estAlignmentY,
|
||||
float allowanceFactor) {
|
||||
// Look for an alignment pattern (3 modules in size) around where it
|
||||
// should be
|
||||
|
@ -298,7 +305,4 @@ namespace zxing {
|
|||
AlignmentPatternFinder alignmentFinder(image_, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX
|
||||
- alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, callback_);
|
||||
return alignmentFinder.find();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue