fix various wrong abs; other cleanup

git-svn-id: https://zxing.googlecode.com/svn/trunk@2675 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
smparkes@smparkes.net 2013-04-21 20:01:55 +00:00
parent 64a5f4a664
commit c8a818982f
9 changed files with 105 additions and 101 deletions

View file

@ -28,7 +28,7 @@
#include <sstream> #include <sstream>
#include <cstdlib> #include <cstdlib>
using std::abs;
using zxing::Ref; using zxing::Ref;
using zxing::BitMatrix; using zxing::BitMatrix;
using zxing::ResultPoint; using zxing::ResultPoint;

View file

@ -16,21 +16,27 @@
*/ */
#include <cmath> #include <cmath>
#include <algorithm>
#include <zxing/multi/qrcode/detector/MultiFinderPatternFinder.h> #include <zxing/multi/qrcode/detector/MultiFinderPatternFinder.h>
#include <zxing/DecodeHints.h> #include <zxing/DecodeHints.h>
#include <zxing/ReaderException.h> #include <zxing/ReaderException.h>
/*
#include <algorithm>
#include <stdlib.h>
*/
using std::abs; using std::abs;
using zxing::multi::MultiFinderPatternFinder; using std::min;
using std::sort;
using std::vector;
using zxing::Ref; using zxing::Ref;
using zxing::BitMatrix;
using zxing::ReaderException;
using zxing::qrcode::FinderPattern; using zxing::qrcode::FinderPattern;
using zxing::qrcode::FinderPatternInfo; 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::MAX_MODULE_COUNT_PER_EDGE = 180;
const float MultiFinderPatternFinder::MIN_MODULE_COUNT_PER_EDGE = 9; const float MultiFinderPatternFinder::MIN_MODULE_COUNT_PER_EDGE = 9;
@ -54,7 +60,7 @@ MultiFinderPatternFinder::MultiFinderPatternFinder(Ref<BitMatrix> image,
MultiFinderPatternFinder::~MultiFinderPatternFinder(){} MultiFinderPatternFinder::~MultiFinderPatternFinder(){}
std::vector<Ref<FinderPatternInfo> > MultiFinderPatternFinder::findMulti(DecodeHints const& hints){ vector<Ref<FinderPatternInfo> > MultiFinderPatternFinder::findMulti(DecodeHints const& hints){
bool tryHarder = hints.getTryHarder(); bool tryHarder = hints.getTryHarder();
Ref<BitMatrix> image = image_; // Protected member Ref<BitMatrix> image = image_; // Protected member
int maxI = image->getHeight(); int maxI = image->getHeight();
@ -119,18 +125,18 @@ std::vector<Ref<FinderPatternInfo> > MultiFinderPatternFinder::findMulti(DecodeH
handlePossibleCenter(stateCount, i, maxJ); handlePossibleCenter(stateCount, i, maxJ);
} // end if foundPatternCross } // end if foundPatternCross
} // for i=iSkip-1 ... } // for i=iSkip-1 ...
std::vector<std::vector<Ref<FinderPattern> > > patternInfo = selectBestPatterns(); vector<vector<Ref<FinderPattern> > > patternInfo = selectBestPatterns();
std::vector<Ref<FinderPatternInfo> > result; vector<Ref<FinderPatternInfo> > result;
for (unsigned int i = 0; i < patternInfo.size(); i++) { for (unsigned int i = 0; i < patternInfo.size(); i++) {
std::vector<Ref<FinderPattern> > pattern = patternInfo[i]; vector<Ref<FinderPattern> > pattern = patternInfo[i];
pattern = FinderPatternFinder::orderBestPatterns(pattern); pattern = FinderPatternFinder::orderBestPatterns(pattern);
result.push_back(Ref<FinderPatternInfo>(new FinderPatternInfo(pattern))); result.push_back(Ref<FinderPatternInfo>(new FinderPatternInfo(pattern)));
} }
return result; return result;
} }
std::vector<std::vector<Ref<FinderPattern> > > MultiFinderPatternFinder::selectBestPatterns(){ vector<vector<Ref<FinderPattern> > > MultiFinderPatternFinder::selectBestPatterns(){
std::vector<Ref<FinderPattern> > possibleCenters = possibleCenters_; vector<Ref<FinderPattern> > possibleCenters = possibleCenters_;
int size = possibleCenters.size(); int size = possibleCenters.size();
@ -139,7 +145,7 @@ std::vector<std::vector<Ref<FinderPattern> > > MultiFinderPatternFinder::selectB
throw ReaderException("No code detected"); throw ReaderException("No code detected");
} }
std::vector<std::vector<Ref<FinderPattern> > > results; vector<vector<Ref<FinderPattern> > > results;
/* /*
* Begin HE modifications to safely detect multiple codes of equal size * Begin HE modifications to safely detect multiple codes of equal size
@ -151,7 +157,7 @@ std::vector<std::vector<Ref<FinderPattern> > > MultiFinderPatternFinder::selectB
// Sort by estimated module size to speed up the upcoming checks // Sort by estimated module size to speed up the upcoming checks
//TODO do a sort based on module size //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 * Now lets start: build a list of tuples of three finder locations that
@ -173,7 +179,7 @@ std::vector<std::vector<Ref<FinderPattern> > > MultiFinderPatternFinder::selectB
for (int i2 = i1 + 1; i2 < (size - 1); i2++) { for (int i2 = i1 + 1; i2 < (size - 1); i2++) {
Ref<FinderPattern> p2 = possibleCenters[i2]; Ref<FinderPattern> p2 = possibleCenters[i2];
// Compare the expected module sizes; if they are really off, skip // 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()); float vModSize12A = abs(p1->getEstimatedModuleSize() - p2->getEstimatedModuleSize());
if (vModSize12A > DIFF_MODSIZE_CUTOFF && vModSize12 >= DIFF_MODSIZE_CUTOFF_PERCENT) { if (vModSize12A > DIFF_MODSIZE_CUTOFF && vModSize12 >= DIFF_MODSIZE_CUTOFF_PERCENT) {
// break, since elements are ordered by the module size deviation there cannot be // break, since elements are ordered by the module size deviation there cannot be
@ -183,14 +189,14 @@ std::vector<std::vector<Ref<FinderPattern> > > MultiFinderPatternFinder::selectB
for (int i3 = i2 + 1; i3 < size; i3++) { for (int i3 = i2 + 1; i3 < size; i3++) {
Ref<FinderPattern> p3 = possibleCenters[i3]; Ref<FinderPattern> p3 = possibleCenters[i3];
// Compare the expected module sizes; if they are really off, skip // 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()); float vModSize23A = abs(p2->getEstimatedModuleSize() - p3->getEstimatedModuleSize());
if (vModSize23A > DIFF_MODSIZE_CUTOFF && vModSize23 >= DIFF_MODSIZE_CUTOFF_PERCENT) { if (vModSize23A > DIFF_MODSIZE_CUTOFF && vModSize23 >= DIFF_MODSIZE_CUTOFF_PERCENT) {
// break, since elements are ordered by the module size deviation there cannot be // break, since elements are ordered by the module size deviation there cannot be
// any more interesting elements for the given p1. // any more interesting elements for the given p1.
break; break;
} }
std::vector<Ref<FinderPattern> > test; vector<Ref<FinderPattern> > test;
test.push_back(p1); test.push_back(p1);
test.push_back(p2); test.push_back(p2);
test.push_back(p3); test.push_back(p3);
@ -206,14 +212,14 @@ std::vector<std::vector<Ref<FinderPattern> > > MultiFinderPatternFinder::selectB
continue; continue;
} }
// Calculate the difference of the edge lengths in percent // 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) { if (vABBC >= 0.1f) {
continue; continue;
} }
// Calculate the diagonal length by assuming a 90° angle at topleft // Calculate the diagonal length by assuming a 90° angle at topleft
float dCpy = (float) sqrt(dA * dA + dB * dB); float dCpy = (float) sqrt(dA * dA + dB * dB);
// Compare to the real distance in % // 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) { if (vPyC >= 0.1f) {
continue; continue;
} }

View file

@ -23,6 +23,7 @@
#include <zxing/common/detector/MathUtils.h> #include <zxing/common/detector/MathUtils.h>
using std::max; using std::max;
using std::abs;
using std::numeric_limits; using std::numeric_limits;
using zxing::pdf417::detector::Detector; using zxing::pdf417::detector::Detector;
using zxing::common::detector::Math; using zxing::common::detector::Math;

View file

@ -24,6 +24,7 @@
using std::map; using std::map;
using std::vector; using std::vector;
using std::min; using std::min;
using std::abs;
using zxing::pdf417::detector::LinesSampler; using zxing::pdf417::detector::LinesSampler;
using zxing::pdf417::decoder::BitMatrixParser; using zxing::pdf417::decoder::BitMatrixParser;
using zxing::Ref; using zxing::Ref;

View file

@ -21,10 +21,9 @@
#include <zxing/qrcode/detector/AlignmentPattern.h> #include <zxing/qrcode/detector/AlignmentPattern.h>
namespace zxing { using std::abs;
namespace qrcode { using zxing::Ref;
using zxing::qrcode::AlignmentPattern;
using namespace std;
AlignmentPattern::AlignmentPattern(float posX, float posY, float estimatedModuleSize) : AlignmentPattern::AlignmentPattern(float posX, float posY, float estimatedModuleSize) :
ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize) { ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize) {
@ -46,6 +45,3 @@ Ref<AlignmentPattern> AlignmentPattern::combineEstimate(float i, float j, float
(new AlignmentPattern(combinedX, combinedY, combinedModuleSize)); (new AlignmentPattern(combinedX, combinedY, combinedModuleSize));
return result; return result;
} }
}
}

View file

@ -1,9 +1,5 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- // -*- 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. * Copyright 2008 ZXing authors All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -19,17 +15,23 @@
* limitations under the License. * limitations under the License.
*/ */
#include "AlignmentPatternFinder.h" #include <zxing/qrcode/detector/AlignmentPatternFinder.h>
#include <zxing/ReaderException.h> #include <zxing/ReaderException.h>
#include <zxing/common/BitArray.h> #include <zxing/common/BitArray.h>
#include <vector> #include <vector>
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
namespace zxing { using std::abs;
namespace qrcode { using std::vector;
using zxing::Ref;
using zxing::qrcode::AlignmentPatternFinder;
using zxing::qrcode::AlignmentPattern;
using namespace std; // VC++
using zxing::BitMatrix;
using zxing::ResultPointCallback;
float AlignmentPatternFinder::centerFromEnd(vector<int>& stateCount, int end) { float AlignmentPatternFinder::centerFromEnd(vector<int>& stateCount, int end) {
return (float)(end - stateCount[2]) - stateCount[1] / 2.0f; return (float)(end - stateCount[2]) - stateCount[1] / 2.0f;
@ -204,6 +206,3 @@ Ref<AlignmentPattern> AlignmentPatternFinder::find() {
throw zxing::ReaderException("Could not find alignment pattern"); throw zxing::ReaderException("Could not find alignment pattern");
} }
}
}

View file

@ -31,8 +31,8 @@
#include <sstream> #include <sstream>
#include <cstdlib> #include <cstdlib>
using std::ostringstream; using std::ostringstream;
using std::abs;
using std::min; using std::min;
using std::max; using std::max;
using zxing::isnan; using zxing::isnan;

View file

@ -21,21 +21,15 @@
#include <zxing/qrcode/detector/FinderPattern.h> #include <zxing/qrcode/detector/FinderPattern.h>
namespace zxing { using std::abs;
namespace qrcode { using zxing::Ref;
using zxing::qrcode::FinderPattern;
using namespace std; FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize)
: ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize), count_(1) {}
FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize) : FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize, int count)
ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize), count_(1) { : ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize), count_(count) {}
// cerr << "fpc " << getX() << " " << getY() << " " << count_ << endl;
// cerr << "fp " << getX() << " " << getY() << endl;
}
FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize, int count) :
ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize), count_(count) {
// cerr << "fpc " << getX() << " " << getY() << " " << count << endl;
}
int FinderPattern::getCount() const { int FinderPattern::getCount() const {
return count_; return count_;
@ -72,6 +66,4 @@ namespace zxing {
float combinedY = (count_ * getY() + i) / combinedCount; float combinedY = (count_ * getY() + i) / combinedCount;
float combinedModuleSize = (count_ * getEstimatedModuleSize() + newModuleSize) / combinedCount; float combinedModuleSize = (count_ * getEstimatedModuleSize() + newModuleSize) / combinedCount;
return Ref<FinderPattern>(new FinderPattern(combinedX, combinedY, combinedModuleSize, combinedCount)); return Ref<FinderPattern>(new FinderPattern(combinedX, combinedY, combinedModuleSize, combinedCount));
}
}
} }

View file

@ -19,18 +19,28 @@
* limitations under the License. * limitations under the License.
*/ */
#include <algorithm>
#include <zxing/qrcode/detector/FinderPatternFinder.h> #include <zxing/qrcode/detector/FinderPatternFinder.h>
#include <zxing/ReaderException.h> #include <zxing/ReaderException.h>
#include <zxing/DecodeHints.h> #include <zxing/DecodeHints.h>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
namespace zxing { using std::sort;
namespace qrcode { 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 { class FurthestFromAverageComparator {
private: private:
@ -64,6 +74,8 @@ public:
} }
}; };
}
int FinderPatternFinder::CENTER_QUORUM = 2; int FinderPatternFinder::CENTER_QUORUM = 2;
int FinderPatternFinder::MIN_SKIP = 3; int FinderPatternFinder::MIN_SKIP = 3;
int FinderPatternFinder::MAX_MODULES = 57; int FinderPatternFinder::MAX_MODULES = 57;
@ -542,9 +554,6 @@ Ref<BitMatrix> FinderPatternFinder::getImage() {
return image_; return image_;
} }
std::vector<Ref<FinderPattern> >& FinderPatternFinder::getPossibleCenters() { vector<Ref<FinderPattern> >& FinderPatternFinder::getPossibleCenters() {
return possibleCenters_; return possibleCenters_;
} }
}
}