mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
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:
parent
64a5f4a664
commit
c8a818982f
|
@ -28,7 +28,7 @@
|
|||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
using std::abs;
|
||||
using zxing::Ref;
|
||||
using zxing::BitMatrix;
|
||||
using zxing::ResultPoint;
|
||||
|
|
|
@ -16,21 +16,27 @@
|
|||
*/
|
||||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <zxing/multi/qrcode/detector/MultiFinderPatternFinder.h>
|
||||
#include <zxing/DecodeHints.h>
|
||||
#include <zxing/ReaderException.h>
|
||||
|
||||
/*
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
|
||||
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<BitMatrix> image,
|
|||
|
||||
MultiFinderPatternFinder::~MultiFinderPatternFinder(){}
|
||||
|
||||
std::vector<Ref<FinderPatternInfo> > MultiFinderPatternFinder::findMulti(DecodeHints const& hints){
|
||||
vector<Ref<FinderPatternInfo> > MultiFinderPatternFinder::findMulti(DecodeHints const& hints){
|
||||
bool tryHarder = hints.getTryHarder();
|
||||
Ref<BitMatrix> image = image_; // Protected member
|
||||
int maxI = image->getHeight();
|
||||
|
@ -119,18 +125,18 @@ std::vector<Ref<FinderPatternInfo> > MultiFinderPatternFinder::findMulti(DecodeH
|
|||
handlePossibleCenter(stateCount, i, maxJ);
|
||||
} // end if foundPatternCross
|
||||
} // for i=iSkip-1 ...
|
||||
std::vector<std::vector<Ref<FinderPattern> > > patternInfo = selectBestPatterns();
|
||||
std::vector<Ref<FinderPatternInfo> > result;
|
||||
vector<vector<Ref<FinderPattern> > > patternInfo = selectBestPatterns();
|
||||
vector<Ref<FinderPatternInfo> > result;
|
||||
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);
|
||||
result.push_back(Ref<FinderPatternInfo>(new FinderPatternInfo(pattern)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::vector<Ref<FinderPattern> > > MultiFinderPatternFinder::selectBestPatterns(){
|
||||
std::vector<Ref<FinderPattern> > possibleCenters = possibleCenters_;
|
||||
vector<vector<Ref<FinderPattern> > > MultiFinderPatternFinder::selectBestPatterns(){
|
||||
vector<Ref<FinderPattern> > possibleCenters = possibleCenters_;
|
||||
|
||||
int size = possibleCenters.size();
|
||||
|
||||
|
@ -139,7 +145,7 @@ std::vector<std::vector<Ref<FinderPattern> > > MultiFinderPatternFinder::selectB
|
|||
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
|
||||
|
@ -151,7 +157,7 @@ std::vector<std::vector<Ref<FinderPattern> > > 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<std::vector<Ref<FinderPattern> > > MultiFinderPatternFinder::selectB
|
|||
for (int i2 = i1 + 1; i2 < (size - 1); i2++) {
|
||||
Ref<FinderPattern> 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<std::vector<Ref<FinderPattern> > > MultiFinderPatternFinder::selectB
|
|||
for (int i3 = i2 + 1; i3 < size; i3++) {
|
||||
Ref<FinderPattern> 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<Ref<FinderPattern> > test;
|
||||
vector<Ref<FinderPattern> > test;
|
||||
test.push_back(p1);
|
||||
test.push_back(p2);
|
||||
test.push_back(p3);
|
||||
|
@ -206,14 +212,14 @@ std::vector<std::vector<Ref<FinderPattern> > > 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;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <zxing/common/detector/MathUtils.h>
|
||||
|
||||
using std::max;
|
||||
using std::abs;
|
||||
using std::numeric_limits;
|
||||
using zxing::pdf417::detector::Detector;
|
||||
using zxing::common::detector::Math;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -21,10 +21,9 @@
|
|||
|
||||
#include <zxing/qrcode/detector/AlignmentPattern.h>
|
||||
|
||||
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> AlignmentPattern::combineEstimate(float i, float j, float
|
|||
float combinedY = (getY() + i) / 2.0f;
|
||||
float combinedModuleSize = (estimatedModuleSize_ + newModuleSize) / 2.0f;
|
||||
Ref<AlignmentPattern> result
|
||||
(new AlignmentPattern(combinedX, combinedY, combinedModuleSize));
|
||||
(new AlignmentPattern(combinedX, combinedY, combinedModuleSize));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <zxing/qrcode/detector/AlignmentPatternFinder.h>
|
||||
#include <zxing/ReaderException.h>
|
||||
#include <zxing/common/BitArray.h>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
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<int> &stateCount, int end) {
|
||||
using zxing::BitMatrix;
|
||||
using zxing::ResultPointCallback;
|
||||
|
||||
float AlignmentPatternFinder::centerFromEnd(vector<int>& stateCount, int end) {
|
||||
return (float)(end - stateCount[2]) - stateCount[1] / 2.0f;
|
||||
}
|
||||
|
||||
|
@ -46,7 +48,7 @@ bool AlignmentPatternFinder::foundPatternCross(vector<int> &stateCount) {
|
|||
}
|
||||
|
||||
float AlignmentPatternFinder::crossCheckVertical(int startI, int centerJ, int maxCount,
|
||||
int originalStateCountTotal) {
|
||||
int originalStateCountTotal) {
|
||||
int maxI = image_->getHeight();
|
||||
vector<int> stateCount(3, 0);
|
||||
|
||||
|
@ -204,6 +206,3 @@ Ref<AlignmentPattern> AlignmentPatternFinder::find() {
|
|||
|
||||
throw zxing::ReaderException("Could not find alignment pattern");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
using std::ostringstream;
|
||||
using std::abs;
|
||||
using std::min;
|
||||
using std::max;
|
||||
using zxing::isnan;
|
||||
|
|
|
@ -21,57 +21,49 @@
|
|||
|
||||
#include <zxing/qrcode/detector/FinderPattern.h>
|
||||
|
||||
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> 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<FinderPattern>(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> 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<FinderPattern>(new FinderPattern(combinedX, combinedY, combinedModuleSize, combinedCount));
|
||||
}
|
||||
|
|
|
@ -19,18 +19,28 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <zxing/qrcode/detector/FinderPatternFinder.h>
|
||||
#include <zxing/ReaderException.h>
|
||||
#include <zxing/DecodeHints.h>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <algorithm>
|
||||
|
||||
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<Ref<FinderPattern> > FinderPatternFinder::selectBestPatterns() {
|
||||
vector< Ref<FinderPattern> > FinderPatternFinder::selectBestPatterns() {
|
||||
size_t startSize = possibleCenters_.size();
|
||||
|
||||
if (startSize < 3) {
|
||||
|
@ -542,9 +554,6 @@ Ref<BitMatrix> FinderPatternFinder::getImage() {
|
|||
return image_;
|
||||
}
|
||||
|
||||
std::vector<Ref<FinderPattern> >& FinderPatternFinder::getPossibleCenters() {
|
||||
vector<Ref<FinderPattern> >& FinderPatternFinder::getPossibleCenters() {
|
||||
return possibleCenters_;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue