mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 13:04:05 -08:00
port r1875 to C++
git-svn-id: https://zxing.googlecode.com/svn/trunk@1959 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
d2ed7976ef
commit
b72031d6e8
|
@ -1,3 +1,4 @@
|
||||||
|
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||||
/*
|
/*
|
||||||
* AlignmentPattern.cpp
|
* AlignmentPattern.cpp
|
||||||
* zxing
|
* zxing
|
||||||
|
@ -38,8 +39,20 @@ float AlignmentPattern::getY() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AlignmentPattern::aboutEquals(float moduleSize, float i, float j) const {
|
bool AlignmentPattern::aboutEquals(float moduleSize, float i, float j) const {
|
||||||
return abs(i - posY_) <= moduleSize && abs(j - posX_) <= moduleSize && (abs(moduleSize - estimatedModuleSize_)
|
if (abs(i - getY()) <= moduleSize && abs(j - getX()) <= moduleSize) {
|
||||||
<= 1.0f || abs(moduleSize - estimatedModuleSize_) / estimatedModuleSize_ <= 0.1f);
|
float moduleSizeDiff = abs(moduleSize - estimatedModuleSize_);
|
||||||
|
return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize_;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<AlignmentPattern> AlignmentPattern::combineEstimate(float i, float j, float newModuleSize) const {
|
||||||
|
float combinedX = (getX() + j) / 2.0f;
|
||||||
|
float combinedY = (getY() + i) / 2.0f;
|
||||||
|
float combinedModuleSize = (estimatedModuleSize_ + newModuleSize) / 2.0f;
|
||||||
|
Ref<AlignmentPattern> result
|
||||||
|
(new AlignmentPattern(combinedX, combinedY, combinedModuleSize));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||||
|
|
||||||
#ifndef __ALIGNMENT_PATTERN_H__
|
#ifndef __ALIGNMENT_PATTERN_H__
|
||||||
#define __ALIGNMENT_PATTERN_H__
|
#define __ALIGNMENT_PATTERN_H__
|
||||||
|
|
||||||
|
@ -37,6 +39,8 @@ namespace zxing {
|
||||||
float getX() const;
|
float getX() const;
|
||||||
float getY() const;
|
float getY() const;
|
||||||
bool aboutEquals(float moduleSize, float i, float j) const;
|
bool aboutEquals(float moduleSize, float i, float j) const;
|
||||||
|
Ref<AlignmentPattern> combineEstimate(float i, float j,
|
||||||
|
float newModuleSize) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||||
/*
|
/*
|
||||||
* AlignmentPatternFinder.cpp
|
* AlignmentPatternFinder.cpp
|
||||||
* zxing
|
* zxing
|
||||||
|
@ -104,8 +105,7 @@ Ref<AlignmentPattern> AlignmentPatternFinder::handlePossibleCenter(vector<int> &
|
||||||
Ref<AlignmentPattern> center((*possibleCenters_)[index]);
|
Ref<AlignmentPattern> center((*possibleCenters_)[index]);
|
||||||
// Look for about the same center and module size:
|
// Look for about the same center and module size:
|
||||||
if (center->aboutEquals(estimatedModuleSize, centerI, centerJ)) {
|
if (center->aboutEquals(estimatedModuleSize, centerI, centerJ)) {
|
||||||
Ref<AlignmentPattern> result(new AlignmentPattern(centerJ, centerI, estimatedModuleSize));
|
return center->combineEstimate(centerI, centerJ, estimatedModuleSize);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AlignmentPattern *tmp = new AlignmentPattern(centerJ, centerI, estimatedModuleSize);
|
AlignmentPattern *tmp = new AlignmentPattern(centerJ, centerI, estimatedModuleSize);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||||
/*
|
/*
|
||||||
* FinderPattern.cpp
|
* FinderPattern.cpp
|
||||||
* zxing
|
* zxing
|
||||||
|
@ -26,7 +27,11 @@ namespace zxing {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize) :
|
FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize) :
|
||||||
posX_(posX), posY_(posY), estimatedModuleSize_(estimatedModuleSize), counter_(1) {
|
posX_(posX), posY_(posY), estimatedModuleSize_(estimatedModuleSize), count_(1) {
|
||||||
|
}
|
||||||
|
|
||||||
|
FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize, int count) :
|
||||||
|
posX_(posX), posY_(posY), estimatedModuleSize_(estimatedModuleSize), count_(count) {
|
||||||
}
|
}
|
||||||
|
|
||||||
float FinderPattern::getX() const {
|
float FinderPattern::getX() const {
|
||||||
|
@ -38,7 +43,7 @@ namespace zxing {
|
||||||
}
|
}
|
||||||
|
|
||||||
int FinderPattern::getCount() const {
|
int FinderPattern::getCount() const {
|
||||||
return counter_;
|
return count_;
|
||||||
}
|
}
|
||||||
|
|
||||||
float FinderPattern::getEstimatedModuleSize() const {
|
float FinderPattern::getEstimatedModuleSize() const {
|
||||||
|
@ -46,13 +51,29 @@ namespace zxing {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FinderPattern::incrementCount() {
|
void FinderPattern::incrementCount() {
|
||||||
counter_++;
|
count_++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
bool FinderPattern::aboutEquals(float moduleSize, float i, float j) const {
|
bool FinderPattern::aboutEquals(float moduleSize, float i, float j) const {
|
||||||
return abs(i - posY_) <= moduleSize && abs(j - posX_) <= moduleSize && (abs(moduleSize - estimatedModuleSize_)
|
return abs(i - posY_) <= moduleSize && abs(j - posX_) <= moduleSize && (abs(moduleSize - estimatedModuleSize_)
|
||||||
<= 1.0f || abs(moduleSize - estimatedModuleSize_) / estimatedModuleSize_ <= 0.1f);
|
<= 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 {
|
||||||
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||||
#ifndef __FINDER_PATTERN_H__
|
#ifndef __FINDER_PATTERN_H__
|
||||||
#define __FINDER_PATTERN_H__
|
#define __FINDER_PATTERN_H__
|
||||||
|
|
||||||
|
@ -31,16 +32,18 @@ namespace zxing {
|
||||||
float posX_;
|
float posX_;
|
||||||
float posY_;
|
float posY_;
|
||||||
float estimatedModuleSize_;
|
float estimatedModuleSize_;
|
||||||
int counter_;
|
int count_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FinderPattern(float posX, float posY, float estimatedModuleSize);
|
FinderPattern(float posX, float posY, float estimatedModuleSize);
|
||||||
|
FinderPattern(float posX, float posY, float estimatedModuleSize, int count);
|
||||||
float getX() const;
|
float getX() const;
|
||||||
float getY() const;
|
float getY() const;
|
||||||
int getCount() const;
|
int getCount() const;
|
||||||
float getEstimatedModuleSize() const;
|
float getEstimatedModuleSize() const;
|
||||||
void incrementCount();
|
void incrementCount();
|
||||||
bool aboutEquals(float moduleSize, float i, float j) const;
|
bool aboutEquals(float moduleSize, float i, float j) const;
|
||||||
|
Ref<FinderPattern> combineEstimate(float i, float j, float newModuleSize) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||||
/*
|
/*
|
||||||
* FinderPatternFinder.cpp
|
* FinderPatternFinder.cpp
|
||||||
* zxing
|
* zxing
|
||||||
|
@ -236,7 +237,7 @@ bool FinderPatternFinder::handlePossibleCenter(int* stateCount, size_t i, size_t
|
||||||
Ref<FinderPattern> center = possibleCenters_[index];
|
Ref<FinderPattern> center = possibleCenters_[index];
|
||||||
// Look for about the same center and module size:
|
// Look for about the same center and module size:
|
||||||
if (center->aboutEquals(estimatedModuleSize, centerI, centerJ)) {
|
if (center->aboutEquals(estimatedModuleSize, centerI, centerJ)) {
|
||||||
center->incrementCount();
|
possibleCenters_[index] = center->combineEstimate(centerI, centerJ, estimatedModuleSize);
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue