mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Bring C++ datamatrix to parity w/Java wrt to the blackbox test
Plus a little whitespace cleanup and make resultpoint immutable. git-svn-id: https://zxing.googlecode.com/svn/trunk@2490 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
7a82d685a3
commit
c8e2721f7d
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
|
|
||||||
|
NotFoundException::NotFoundException() {}
|
||||||
|
|
||||||
NotFoundException::NotFoundException(const char *msg)
|
NotFoundException::NotFoundException(const char *msg)
|
||||||
: ReaderException(msg) {}
|
: ReaderException(msg) {}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace zxing {
|
||||||
|
|
||||||
class NotFoundException : public ReaderException {
|
class NotFoundException : public ReaderException {
|
||||||
public:
|
public:
|
||||||
|
NotFoundException();
|
||||||
NotFoundException(const char *msg);
|
NotFoundException(const char *msg);
|
||||||
~NotFoundException() throw();
|
~NotFoundException() throw();
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,8 +28,8 @@ namespace zxing {
|
||||||
|
|
||||||
class ResultPoint : public Counted {
|
class ResultPoint : public Counted {
|
||||||
protected:
|
protected:
|
||||||
float posX_;
|
const float posX_;
|
||||||
float posY_;
|
const float posY_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ResultPoint();
|
ResultPoint();
|
||||||
|
|
|
@ -19,19 +19,33 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <zxing/ResultPoint.h>
|
#include <zxing/ResultPoint.h>
|
||||||
#include <zxing/common/GridSampler.h>
|
#include <zxing/common/GridSampler.h>
|
||||||
#include <zxing/datamatrix/detector/Detector.h>
|
#include <zxing/datamatrix/detector/Detector.h>
|
||||||
#include <zxing/common/detector/math_utils.h>
|
#include <zxing/common/detector/math_utils.h>
|
||||||
|
#include <zxing/NotFoundException.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace math_utils = zxing::common::detector::math_utils;
|
namespace math_utils = zxing::common::detector::math_utils;
|
||||||
|
|
||||||
namespace zxing {
|
using zxing::Ref;
|
||||||
namespace datamatrix {
|
using zxing::BitMatrix;
|
||||||
|
using zxing::ResultPoint;
|
||||||
|
using zxing::DetectorResult;
|
||||||
|
using zxing::PerspectiveTransform;
|
||||||
|
using zxing::NotFoundException;
|
||||||
|
using zxing::datamatrix::Detector;
|
||||||
|
using zxing::datamatrix::ResultPointsAndTransitions;
|
||||||
|
|
||||||
using namespace std;
|
namespace {
|
||||||
|
typedef std::map<Ref<ResultPoint>, int> PointMap;
|
||||||
|
void increment(PointMap& table, Ref<ResultPoint> const& key) {
|
||||||
|
int& value = table[key];
|
||||||
|
value += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ResultPointsAndTransitions::ResultPointsAndTransitions() {
|
ResultPointsAndTransitions::ResultPointsAndTransitions() {
|
||||||
Ref<ResultPoint> ref(new ResultPoint(0, 0));
|
Ref<ResultPoint> ref(new ResultPoint(0, 0));
|
||||||
|
@ -88,35 +102,37 @@ Ref<DetectorResult> Detector::detect() {
|
||||||
Ref<ResultPointsAndTransitions> lSideOne(transitions[0]);
|
Ref<ResultPointsAndTransitions> lSideOne(transitions[0]);
|
||||||
Ref<ResultPointsAndTransitions> lSideTwo(transitions[1]);
|
Ref<ResultPointsAndTransitions> lSideTwo(transitions[1]);
|
||||||
|
|
||||||
|
// Figure out which point is their intersection by tallying up the number of times we see the
|
||||||
|
// endpoints in the four endpoints. One will show up twice.
|
||||||
|
typedef std::map<Ref<ResultPoint>, int> PointMap;
|
||||||
|
PointMap pointCount;
|
||||||
|
increment(pointCount, lSideOne->getFrom());
|
||||||
|
increment(pointCount, lSideOne->getTo());
|
||||||
|
increment(pointCount, lSideTwo->getFrom());
|
||||||
|
increment(pointCount, lSideTwo->getTo());
|
||||||
|
|
||||||
// Figure out which point is their intersection by tallying up the number of times we see the
|
// Figure out which point is their intersection by tallying up the number of times we see the
|
||||||
// endpoints in the four endpoints. One will show up twice.
|
// endpoints in the four endpoints. One will show up twice.
|
||||||
Ref<ResultPoint> maybeTopLeft;
|
Ref<ResultPoint> maybeTopLeft;
|
||||||
Ref<ResultPoint> bottomLeft;
|
Ref<ResultPoint> bottomLeft;
|
||||||
Ref<ResultPoint> maybeBottomRight;
|
Ref<ResultPoint> maybeBottomRight;
|
||||||
if (lSideOne->getFrom()->equals(lSideOne->getTo())) {
|
for (PointMap::const_iterator entry = pointCount.begin(), end = pointCount.end(); entry != end; ++entry) {
|
||||||
bottomLeft = lSideOne->getFrom();
|
Ref<ResultPoint> const& point = entry->first;
|
||||||
maybeTopLeft = lSideTwo->getFrom();
|
int value = entry->second;
|
||||||
maybeBottomRight = lSideTwo->getTo();
|
if (value == 2) {
|
||||||
} else if (lSideOne->getFrom()->equals(lSideTwo->getFrom())) {
|
bottomLeft = point; // this is definitely the bottom left, then -- end of two L sides
|
||||||
bottomLeft = lSideOne->getFrom();
|
|
||||||
maybeTopLeft = lSideOne->getTo();
|
|
||||||
maybeBottomRight = lSideTwo->getTo();
|
|
||||||
} else if (lSideOne->getFrom()->equals(lSideTwo->getTo())) {
|
|
||||||
bottomLeft = lSideOne->getFrom();
|
|
||||||
maybeTopLeft = lSideOne->getTo();
|
|
||||||
maybeBottomRight = lSideTwo->getFrom();
|
|
||||||
} else if (lSideOne->getTo()->equals(lSideTwo->getFrom())) {
|
|
||||||
bottomLeft = lSideOne->getTo();
|
|
||||||
maybeTopLeft = lSideOne->getFrom();
|
|
||||||
maybeBottomRight = lSideTwo->getTo();
|
|
||||||
} else if (lSideOne->getTo()->equals(lSideTwo->getTo())) {
|
|
||||||
bottomLeft = lSideOne->getTo();
|
|
||||||
maybeTopLeft = lSideOne->getFrom();
|
|
||||||
maybeBottomRight = lSideTwo->getFrom();
|
|
||||||
} else {
|
} else {
|
||||||
bottomLeft = lSideTwo->getFrom();
|
// Otherwise it's either top left or bottom right -- just assign the two arbitrarily now
|
||||||
maybeTopLeft = lSideOne->getTo();
|
if (maybeTopLeft == 0) {
|
||||||
maybeBottomRight = lSideOne->getFrom();
|
maybeTopLeft = point;
|
||||||
|
} else {
|
||||||
|
maybeBottomRight = point;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maybeTopLeft == 0 || bottomLeft == 0 || maybeBottomRight == 0) {
|
||||||
|
throw NotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bottom left is correct but top left and bottom right might be switched
|
// Bottom left is correct but top left and bottom right might be switched
|
||||||
|
@ -217,7 +233,7 @@ Ref<DetectorResult> Detector::detect() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redetermine the dimension using the corrected top right point
|
// Redetermine the dimension using the corrected top right point
|
||||||
int dimensionCorrected = max(transitionsBetween(topLeft, correctedTopRight)->getTransitions(),
|
int dimensionCorrected = std::max(transitionsBetween(topLeft, correctedTopRight)->getTransitions(),
|
||||||
transitionsBetween(bottomRight, correctedTopRight)->getTransitions());
|
transitionsBetween(bottomRight, correctedTopRight)->getTransitions());
|
||||||
dimensionCorrected++;
|
dimensionCorrected++;
|
||||||
if ((dimensionCorrected & 0x01) == 1) {
|
if ((dimensionCorrected & 0x01) == 1) {
|
||||||
|
@ -428,5 +444,3 @@ void Detector::insertionSort(std::vector<Ref<ResultPointsAndTransitions> > &vect
|
||||||
int Detector::compare(Ref<ResultPointsAndTransitions> a, Ref<ResultPointsAndTransitions> b) {
|
int Detector::compare(Ref<ResultPointsAndTransitions> a, Ref<ResultPointsAndTransitions> b) {
|
||||||
return a->getTransitions() - b->getTransitions();
|
return a->getTransitions() - b->getTransitions();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue