From c8a818982f2861cd95f59c198ab206a26ac7a8ea Mon Sep 17 00:00:00 2001 From: "smparkes@smparkes.net" Date: Sun, 21 Apr 2013 20:01:55 +0000 Subject: [PATCH] fix various wrong abs; other cleanup git-svn-id: https://zxing.googlecode.com/svn/trunk@2675 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../zxing/datamatrix/detector/Detector.cpp | 2 +- .../detector/MultiFinderPatternFinder.cpp | 46 +++++----- .../src/zxing/pdf417/detector/Detector.cpp | 1 + .../zxing/pdf417/detector/LinesSampler.cpp | 1 + .../qrcode/detector/AlignmentPattern.cpp | 12 +-- .../detector/AlignmentPatternFinder.cpp | 25 +++--- .../src/zxing/qrcode/detector/Detector.cpp | 2 +- .../zxing/qrcode/detector/FinderPattern.cpp | 84 +++++++++---------- .../qrcode/detector/FinderPatternFinder.cpp | 33 +++++--- 9 files changed, 105 insertions(+), 101 deletions(-) diff --git a/cpp/core/src/zxing/datamatrix/detector/Detector.cpp b/cpp/core/src/zxing/datamatrix/detector/Detector.cpp index ac91ff0ce..36c427c24 100644 --- a/cpp/core/src/zxing/datamatrix/detector/Detector.cpp +++ b/cpp/core/src/zxing/datamatrix/detector/Detector.cpp @@ -28,7 +28,7 @@ #include #include - +using std::abs; using zxing::Ref; using zxing::BitMatrix; using zxing::ResultPoint; diff --git a/cpp/core/src/zxing/multi/qrcode/detector/MultiFinderPatternFinder.cpp b/cpp/core/src/zxing/multi/qrcode/detector/MultiFinderPatternFinder.cpp index cc7815291..edc825f01 100644 --- a/cpp/core/src/zxing/multi/qrcode/detector/MultiFinderPatternFinder.cpp +++ b/cpp/core/src/zxing/multi/qrcode/detector/MultiFinderPatternFinder.cpp @@ -16,21 +16,27 @@ */ #include +#include #include #include #include -/* - #include - #include -*/ - using std::abs; -using zxing::multi::MultiFinderPatternFinder; +using std::min; +using std::sort; +using std::vector; using zxing::Ref; +using zxing::BitMatrix; +using zxing::ReaderException; using zxing::qrcode::FinderPattern; using zxing::qrcode::FinderPatternInfo; -using zxing::ReaderException; +using zxing::multi::MultiFinderPatternFinder; + +// VC++ + +using zxing::BitMatrix; +using zxing::ResultPointCallback; +using zxing::DecodeHints; const float MultiFinderPatternFinder::MAX_MODULE_COUNT_PER_EDGE = 180; const float MultiFinderPatternFinder::MIN_MODULE_COUNT_PER_EDGE = 9; @@ -54,7 +60,7 @@ MultiFinderPatternFinder::MultiFinderPatternFinder(Ref image, MultiFinderPatternFinder::~MultiFinderPatternFinder(){} -std::vector > MultiFinderPatternFinder::findMulti(DecodeHints const& hints){ +vector > MultiFinderPatternFinder::findMulti(DecodeHints const& hints){ bool tryHarder = hints.getTryHarder(); Ref image = image_; // Protected member int maxI = image->getHeight(); @@ -119,18 +125,18 @@ std::vector > MultiFinderPatternFinder::findMulti(DecodeH handlePossibleCenter(stateCount, i, maxJ); } // end if foundPatternCross } // for i=iSkip-1 ... - std::vector > > patternInfo = selectBestPatterns(); - std::vector > result; + vector > > patternInfo = selectBestPatterns(); + vector > result; for (unsigned int i = 0; i < patternInfo.size(); i++) { - std::vector > pattern = patternInfo[i]; + vector > pattern = patternInfo[i]; pattern = FinderPatternFinder::orderBestPatterns(pattern); result.push_back(Ref(new FinderPatternInfo(pattern))); } return result; } -std::vector > > MultiFinderPatternFinder::selectBestPatterns(){ - std::vector > possibleCenters = possibleCenters_; +vector > > MultiFinderPatternFinder::selectBestPatterns(){ + vector > possibleCenters = possibleCenters_; int size = possibleCenters.size(); @@ -139,7 +145,7 @@ std::vector > > MultiFinderPatternFinder::selectB throw ReaderException("No code detected"); } - std::vector > > results; + vector > > results; /* * Begin HE modifications to safely detect multiple codes of equal size @@ -151,7 +157,7 @@ std::vector > > MultiFinderPatternFinder::selectB // Sort by estimated module size to speed up the upcoming checks //TODO do a sort based on module size - std::sort(possibleCenters.begin(), possibleCenters.end(), compareModuleSize); + sort(possibleCenters.begin(), possibleCenters.end(), compareModuleSize); /* * Now lets start: build a list of tuples of three finder locations that @@ -173,7 +179,7 @@ std::vector > > MultiFinderPatternFinder::selectB for (int i2 = i1 + 1; i2 < (size - 1); i2++) { Ref p2 = possibleCenters[i2]; // Compare the expected module sizes; if they are really off, skip - float vModSize12 = (p1->getEstimatedModuleSize() - p2->getEstimatedModuleSize()) / std::min(p1->getEstimatedModuleSize(), p2->getEstimatedModuleSize()); + float vModSize12 = (p1->getEstimatedModuleSize() - p2->getEstimatedModuleSize()) / min(p1->getEstimatedModuleSize(), p2->getEstimatedModuleSize()); float vModSize12A = abs(p1->getEstimatedModuleSize() - p2->getEstimatedModuleSize()); if (vModSize12A > DIFF_MODSIZE_CUTOFF && vModSize12 >= DIFF_MODSIZE_CUTOFF_PERCENT) { // break, since elements are ordered by the module size deviation there cannot be @@ -183,14 +189,14 @@ std::vector > > MultiFinderPatternFinder::selectB for (int i3 = i2 + 1; i3 < size; i3++) { Ref p3 = possibleCenters[i3]; // Compare the expected module sizes; if they are really off, skip - float vModSize23 = (p2->getEstimatedModuleSize() - p3->getEstimatedModuleSize()) / std::min(p2->getEstimatedModuleSize(), p3->getEstimatedModuleSize()); + float vModSize23 = (p2->getEstimatedModuleSize() - p3->getEstimatedModuleSize()) / min(p2->getEstimatedModuleSize(), p3->getEstimatedModuleSize()); float vModSize23A = abs(p2->getEstimatedModuleSize() - p3->getEstimatedModuleSize()); if (vModSize23A > DIFF_MODSIZE_CUTOFF && vModSize23 >= DIFF_MODSIZE_CUTOFF_PERCENT) { // break, since elements are ordered by the module size deviation there cannot be // any more interesting elements for the given p1. break; } - std::vector > test; + vector > test; test.push_back(p1); test.push_back(p2); test.push_back(p3); @@ -206,14 +212,14 @@ std::vector > > MultiFinderPatternFinder::selectB continue; } // Calculate the difference of the edge lengths in percent - float vABBC = abs((dA - dB) / std::min(dA, dB)); + float vABBC = abs((dA - dB) / min(dA, dB)); if (vABBC >= 0.1f) { continue; } // Calculate the diagonal length by assuming a 90° angle at topleft float dCpy = (float) sqrt(dA * dA + dB * dB); // Compare to the real distance in % - float vPyC = abs((dC - dCpy) / std::min(dC, dCpy)); + float vPyC = abs((dC - dCpy) / min(dC, dCpy)); if (vPyC >= 0.1f) { continue; } diff --git a/cpp/core/src/zxing/pdf417/detector/Detector.cpp b/cpp/core/src/zxing/pdf417/detector/Detector.cpp index 18ef8029c..cf22d7774 100644 --- a/cpp/core/src/zxing/pdf417/detector/Detector.cpp +++ b/cpp/core/src/zxing/pdf417/detector/Detector.cpp @@ -23,6 +23,7 @@ #include using std::max; +using std::abs; using std::numeric_limits; using zxing::pdf417::detector::Detector; using zxing::common::detector::Math; diff --git a/cpp/core/src/zxing/pdf417/detector/LinesSampler.cpp b/cpp/core/src/zxing/pdf417/detector/LinesSampler.cpp index 27b459a49..4ec640ea3 100644 --- a/cpp/core/src/zxing/pdf417/detector/LinesSampler.cpp +++ b/cpp/core/src/zxing/pdf417/detector/LinesSampler.cpp @@ -24,6 +24,7 @@ using std::map; using std::vector; using std::min; +using std::abs; using zxing::pdf417::detector::LinesSampler; using zxing::pdf417::decoder::BitMatrixParser; using zxing::Ref; diff --git a/cpp/core/src/zxing/qrcode/detector/AlignmentPattern.cpp b/cpp/core/src/zxing/qrcode/detector/AlignmentPattern.cpp index d8744939e..9ab35eba8 100644 --- a/cpp/core/src/zxing/qrcode/detector/AlignmentPattern.cpp +++ b/cpp/core/src/zxing/qrcode/detector/AlignmentPattern.cpp @@ -21,10 +21,9 @@ #include -namespace zxing { -namespace qrcode { - -using namespace std; +using std::abs; +using zxing::Ref; +using zxing::qrcode::AlignmentPattern; AlignmentPattern::AlignmentPattern(float posX, float posY, float estimatedModuleSize) : ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize) { @@ -43,9 +42,6 @@ Ref AlignmentPattern::combineEstimate(float i, float j, float float combinedY = (getY() + i) / 2.0f; float combinedModuleSize = (estimatedModuleSize_ + newModuleSize) / 2.0f; Ref result - (new AlignmentPattern(combinedX, combinedY, combinedModuleSize)); + (new AlignmentPattern(combinedX, combinedY, combinedModuleSize)); return result; } - -} -} diff --git a/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.cpp b/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.cpp index 63c75c227..8ce4321a9 100644 --- a/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.cpp +++ b/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.cpp @@ -1,9 +1,5 @@ // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* - * AlignmentPatternFinder.cpp - * zxing - * - * Created by Christian Brunschen on 14/05/2008. * Copyright 2008 ZXing authors All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,19 +15,25 @@ * limitations under the License. */ -#include "AlignmentPatternFinder.h" +#include #include #include #include #include #include -namespace zxing { -namespace qrcode { +using std::abs; +using std::vector; +using zxing::Ref; +using zxing::qrcode::AlignmentPatternFinder; +using zxing::qrcode::AlignmentPattern; -using namespace std; +// VC++ -float AlignmentPatternFinder::centerFromEnd(vector &stateCount, int end) { +using zxing::BitMatrix; +using zxing::ResultPointCallback; + +float AlignmentPatternFinder::centerFromEnd(vector& stateCount, int end) { return (float)(end - stateCount[2]) - stateCount[1] / 2.0f; } @@ -46,7 +48,7 @@ bool AlignmentPatternFinder::foundPatternCross(vector &stateCount) { } float AlignmentPatternFinder::crossCheckVertical(int startI, int centerJ, int maxCount, - int originalStateCountTotal) { + int originalStateCountTotal) { int maxI = image_->getHeight(); vector stateCount(3, 0); @@ -204,6 +206,3 @@ Ref AlignmentPatternFinder::find() { throw zxing::ReaderException("Could not find alignment pattern"); } - -} -} diff --git a/cpp/core/src/zxing/qrcode/detector/Detector.cpp b/cpp/core/src/zxing/qrcode/detector/Detector.cpp index 1e84963cc..45531c03d 100644 --- a/cpp/core/src/zxing/qrcode/detector/Detector.cpp +++ b/cpp/core/src/zxing/qrcode/detector/Detector.cpp @@ -31,8 +31,8 @@ #include #include - using std::ostringstream; +using std::abs; using std::min; using std::max; using zxing::isnan; diff --git a/cpp/core/src/zxing/qrcode/detector/FinderPattern.cpp b/cpp/core/src/zxing/qrcode/detector/FinderPattern.cpp index 1701ff5b3..f882cc0e4 100644 --- a/cpp/core/src/zxing/qrcode/detector/FinderPattern.cpp +++ b/cpp/core/src/zxing/qrcode/detector/FinderPattern.cpp @@ -21,57 +21,49 @@ #include -namespace zxing { - namespace qrcode { +using std::abs; +using zxing::Ref; +using zxing::qrcode::FinderPattern; + +FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize) + : ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize), count_(1) {} - using namespace std; +FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize, int count) + : ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize), count_(count) {} - FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize) : - ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize), count_(1) { - // cerr << "fpc " << getX() << " " << getY() << " " << count_ << endl; - // cerr << "fp " << getX() << " " << getY() << endl; - } +int FinderPattern::getCount() const { + return count_; +} - FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize, int count) : - ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize), count_(count) { - // cerr << "fpc " << getX() << " " << getY() << " " << count << endl; - } +float FinderPattern::getEstimatedModuleSize() const { + return estimatedModuleSize_; +} - int FinderPattern::getCount() const { - return count_; - } - - float FinderPattern::getEstimatedModuleSize() const { - return estimatedModuleSize_; - } - - void FinderPattern::incrementCount() { - count_++; - // cerr << "ic " << getX() << " " << getY() << " " << count_ << endl; - } +void FinderPattern::incrementCount() { + count_++; + // cerr << "ic " << getX() << " " << getY() << " " << count_ << endl; +} /* - bool FinderPattern::aboutEquals(float moduleSize, float i, float j) const { - return abs(i - posY_) <= moduleSize && abs(j - posX_) <= moduleSize && (abs(moduleSize - estimatedModuleSize_) - <= 1.0f || abs(moduleSize - estimatedModuleSize_) / estimatedModuleSize_ <= 0.1f); - } + bool FinderPattern::aboutEquals(float moduleSize, float i, float j) const { + return abs(i - posY_) <= moduleSize && abs(j - posX_) <= moduleSize && (abs(moduleSize - estimatedModuleSize_) + <= 1.0f || abs(moduleSize - estimatedModuleSize_) / estimatedModuleSize_ <= 0.1f); + } */ - bool FinderPattern::aboutEquals(float moduleSize, float i, float j) const { - if (abs(i - getY()) <= moduleSize && abs(j - getX()) <= moduleSize) { - float moduleSizeDiff = abs(moduleSize - estimatedModuleSize_); - return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize_; - } - return false; - } - - Ref FinderPattern::combineEstimate(float i, float j, float newModuleSize) const { - // fprintf(stderr, "ce %f %f %f\n", i, j, newModuleSize); - - int combinedCount = count_ + 1; - float combinedX = (count_ * getX() + j) / combinedCount; - float combinedY = (count_ * getY() + i) / combinedCount; - float combinedModuleSize = (count_ * getEstimatedModuleSize() + newModuleSize) / combinedCount; - return Ref(new FinderPattern(combinedX, combinedY, combinedModuleSize, combinedCount)); - } - } +bool FinderPattern::aboutEquals(float moduleSize, float i, float j) const { + if (abs(i - getY()) <= moduleSize && abs(j - getX()) <= moduleSize) { + float moduleSizeDiff = abs(moduleSize - estimatedModuleSize_); + return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize_; + } + return false; +} + +Ref FinderPattern::combineEstimate(float i, float j, float newModuleSize) const { + // fprintf(stderr, "ce %f %f %f\n", i, j, newModuleSize); + + int combinedCount = count_ + 1; + float combinedX = (count_ * getX() + j) / combinedCount; + float combinedY = (count_ * getY() + i) / combinedCount; + float combinedModuleSize = (count_ * getEstimatedModuleSize() + newModuleSize) / combinedCount; + return Ref(new FinderPattern(combinedX, combinedY, combinedModuleSize, combinedCount)); } diff --git a/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp b/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp index c952b2b40..1f3228b71 100644 --- a/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp +++ b/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp @@ -19,18 +19,28 @@ * limitations under the License. */ +#include #include #include #include -#include -#include -#include -#include -namespace zxing { -namespace qrcode { +using std::sort; +using std::max; +using std::abs; +using std::vector; +using zxing::Ref; +using zxing::qrcode::FinderPatternFinder; +using zxing::qrcode::FinderPattern; +using zxing::qrcode::FinderPatternInfo; -using namespace std; +// VC++ + +using zxing::BitMatrix; +using zxing::ResultPointCallback; +using zxing::ResultPoint; +using zxing::DecodeHints; + +namespace { class FurthestFromAverageComparator { private: @@ -64,6 +74,8 @@ public: } }; +} + int FinderPatternFinder::CENTER_QUORUM = 2; int FinderPatternFinder::MIN_SKIP = 3; int FinderPatternFinder::MAX_MODULES = 57; @@ -308,7 +320,7 @@ bool FinderPatternFinder::haveMultiplyConfirmedCenters() { return totalDeviation <= 0.05f * totalModuleSize; } -vector > FinderPatternFinder::selectBestPatterns() { +vector< Ref > FinderPatternFinder::selectBestPatterns() { size_t startSize = possibleCenters_.size(); if (startSize < 3) { @@ -542,9 +554,6 @@ Ref FinderPatternFinder::getImage() { return image_; } -std::vector >& FinderPatternFinder::getPossibleCenters() { +vector >& FinderPatternFinder::getPossibleCenters() { return possibleCenters_; } - -} -}