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
|
@ -1,28 +1,30 @@
|
||||||
// -*- 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 -*-
|
||||||
/*
|
/*
|
||||||
* Copyright 20011 ZXing authors
|
* Copyright 20011 ZXing authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <zxing/NotFoundException.h>
|
#include <zxing/NotFoundException.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
|
|
||||||
NotFoundException::NotFoundException(const char *msg)
|
NotFoundException::NotFoundException() {}
|
||||||
: ReaderException(msg) {}
|
|
||||||
|
NotFoundException::NotFoundException(const char *msg)
|
||||||
NotFoundException::~NotFoundException() throw() {
|
: ReaderException(msg) {}
|
||||||
}
|
|
||||||
|
NotFoundException::~NotFoundException() throw() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,33 +1,34 @@
|
||||||
// -*- 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 -*-
|
||||||
|
|
||||||
#ifndef __NOT_FOUND_EXCEPTION_H__
|
#ifndef __NOT_FOUND_EXCEPTION_H__
|
||||||
#define __NOT_FOUND_EXCEPTION_H__
|
#define __NOT_FOUND_EXCEPTION_H__
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 20011 ZXing authors
|
* Copyright 20011 ZXing authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <zxing/ReaderException.h>
|
#include <zxing/ReaderException.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
|
|
||||||
class NotFoundException : public ReaderException {
|
class NotFoundException : public ReaderException {
|
||||||
public:
|
public:
|
||||||
NotFoundException(const char *msg);
|
NotFoundException();
|
||||||
~NotFoundException() throw();
|
NotFoundException(const char *msg);
|
||||||
};
|
~NotFoundException() throw();
|
||||||
|
};
|
||||||
}
|
|
||||||
#endif // __NOT_FOUND_EXCEPTION_H__
|
}
|
||||||
|
#endif // __NOT_FOUND_EXCEPTION_H__
|
||||||
|
|
|
@ -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));
|
||||||
|
@ -41,8 +55,8 @@ ResultPointsAndTransitions::ResultPointsAndTransitions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultPointsAndTransitions::ResultPointsAndTransitions(Ref<ResultPoint> from, Ref<ResultPoint> to,
|
ResultPointsAndTransitions::ResultPointsAndTransitions(Ref<ResultPoint> from, Ref<ResultPoint> to,
|
||||||
int transitions)
|
int transitions)
|
||||||
: to_(to), from_(from), transitions_(transitions) {
|
: to_(to), from_(from), transitions_(transitions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<ResultPoint> ResultPointsAndTransitions::getFrom() {
|
Ref<ResultPoint> ResultPointsAndTransitions::getFrom() {
|
||||||
|
@ -58,7 +72,7 @@ int ResultPointsAndTransitions::getTransitions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Detector::Detector(Ref<BitMatrix> image)
|
Detector::Detector(Ref<BitMatrix> image)
|
||||||
: image_(image) {
|
: image_(image) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<BitMatrix> Detector::getImage() {
|
Ref<BitMatrix> Detector::getImage() {
|
||||||
|
@ -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();
|
} else {
|
||||||
maybeTopLeft = lSideOne->getTo();
|
// Otherwise it's either top left or bottom right -- just assign the two arbitrarily now
|
||||||
maybeBottomRight = lSideTwo->getTo();
|
if (maybeTopLeft == 0) {
|
||||||
} else if (lSideOne->getFrom()->equals(lSideTwo->getTo())) {
|
maybeTopLeft = point;
|
||||||
bottomLeft = lSideOne->getFrom();
|
} else {
|
||||||
maybeTopLeft = lSideOne->getTo();
|
maybeBottomRight = point;
|
||||||
maybeBottomRight = lSideTwo->getFrom();
|
}
|
||||||
} else if (lSideOne->getTo()->equals(lSideTwo->getFrom())) {
|
}
|
||||||
bottomLeft = lSideOne->getTo();
|
}
|
||||||
maybeTopLeft = lSideOne->getFrom();
|
|
||||||
maybeBottomRight = lSideTwo->getTo();
|
if (maybeTopLeft == 0 || bottomLeft == 0 || maybeBottomRight == 0) {
|
||||||
} else if (lSideOne->getTo()->equals(lSideTwo->getTo())) {
|
throw NotFoundException();
|
||||||
bottomLeft = lSideOne->getTo();
|
|
||||||
maybeTopLeft = lSideOne->getFrom();
|
|
||||||
maybeBottomRight = lSideTwo->getFrom();
|
|
||||||
} else {
|
|
||||||
bottomLeft = lSideTwo->getFrom();
|
|
||||||
maybeTopLeft = lSideOne->getTo();
|
|
||||||
maybeBottomRight = lSideOne->getFrom();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -138,10 +154,10 @@ Ref<DetectorResult> Detector::detect() {
|
||||||
if (!(pointA->equals(bottomRight) || pointA->equals(bottomLeft) || pointA->equals(topLeft))) {
|
if (!(pointA->equals(bottomRight) || pointA->equals(bottomLeft) || pointA->equals(topLeft))) {
|
||||||
topRight = pointA;
|
topRight = pointA;
|
||||||
} else if (!(pointB->equals(bottomRight) || pointB->equals(bottomLeft)
|
} else if (!(pointB->equals(bottomRight) || pointB->equals(bottomLeft)
|
||||||
|| pointB->equals(topLeft))) {
|
|| pointB->equals(topLeft))) {
|
||||||
topRight = pointB;
|
topRight = pointB;
|
||||||
} else if (!(pointC->equals(bottomRight) || pointC->equals(bottomLeft)
|
} else if (!(pointC->equals(bottomRight) || pointC->equals(bottomLeft)
|
||||||
|| pointC->equals(topLeft))) {
|
|| pointC->equals(topLeft))) {
|
||||||
topRight = pointC;
|
topRight = pointC;
|
||||||
} else {
|
} else {
|
||||||
topRight = pointD;
|
topRight = pointD;
|
||||||
|
@ -184,7 +200,7 @@ Ref<DetectorResult> Detector::detect() {
|
||||||
if (4 * dimensionTop >= 7 * dimensionRight || 4 * dimensionRight >= 7 * dimensionTop) {
|
if (4 * dimensionTop >= 7 * dimensionRight || 4 * dimensionRight >= 7 * dimensionTop) {
|
||||||
// The matrix is rectangular
|
// The matrix is rectangular
|
||||||
correctedTopRight = correctTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight,
|
correctedTopRight = correctTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight,
|
||||||
dimensionTop, dimensionRight);
|
dimensionTop, dimensionRight);
|
||||||
if (correctedTopRight == NULL) {
|
if (correctedTopRight == NULL) {
|
||||||
correctedTopRight = topRight;
|
correctedTopRight = topRight;
|
||||||
}
|
}
|
||||||
|
@ -203,7 +219,7 @@ Ref<DetectorResult> Detector::detect() {
|
||||||
}
|
}
|
||||||
|
|
||||||
transform = createTransform(topLeft, correctedTopRight, bottomLeft, bottomRight, dimensionTop,
|
transform = createTransform(topLeft, correctedTopRight, bottomLeft, bottomRight, dimensionTop,
|
||||||
dimensionRight);
|
dimensionRight);
|
||||||
bits = sampleGrid(image_, dimensionTop, dimensionRight, transform);
|
bits = sampleGrid(image_, dimensionTop, dimensionRight, transform);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -217,15 +233,15 @@ 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) {
|
||||||
dimensionCorrected++;
|
dimensionCorrected++;
|
||||||
}
|
}
|
||||||
|
|
||||||
transform = createTransform(topLeft, correctedTopRight, bottomLeft, bottomRight,
|
transform = createTransform(topLeft, correctedTopRight, bottomLeft, bottomRight,
|
||||||
dimensionCorrected, dimensionCorrected);
|
dimensionCorrected, dimensionCorrected);
|
||||||
bits = sampleGrid(image_, dimensionCorrected, dimensionCorrected, transform);
|
bits = sampleGrid(image_, dimensionCorrected, dimensionCorrected, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,8 +259,8 @@ Ref<DetectorResult> Detector::detect() {
|
||||||
* for a rectangular matrix
|
* for a rectangular matrix
|
||||||
*/
|
*/
|
||||||
Ref<ResultPoint> Detector::correctTopRightRectangular(Ref<ResultPoint> bottomLeft,
|
Ref<ResultPoint> Detector::correctTopRightRectangular(Ref<ResultPoint> bottomLeft,
|
||||||
Ref<ResultPoint> bottomRight, Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight,
|
Ref<ResultPoint> bottomRight, Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight,
|
||||||
int dimensionTop, int dimensionRight) {
|
int dimensionTop, int dimensionRight) {
|
||||||
|
|
||||||
float corr = distance(bottomLeft, bottomRight) / (float) dimensionTop;
|
float corr = distance(bottomLeft, bottomRight) / (float) dimensionTop;
|
||||||
int norm = distance(topLeft, topRight);
|
int norm = distance(topLeft, topRight);
|
||||||
|
@ -252,7 +268,7 @@ Ref<ResultPoint> Detector::correctTopRightRectangular(Ref<ResultPoint> bottomLef
|
||||||
float sin = (topRight->getY() - topLeft->getY()) / norm;
|
float sin = (topRight->getY() - topLeft->getY()) / norm;
|
||||||
|
|
||||||
Ref<ResultPoint> c1(
|
Ref<ResultPoint> c1(
|
||||||
new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin));
|
new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin));
|
||||||
|
|
||||||
corr = distance(bottomLeft, topLeft) / (float) dimensionRight;
|
corr = distance(bottomLeft, topLeft) / (float) dimensionRight;
|
||||||
norm = distance(bottomRight, topRight);
|
norm = distance(bottomRight, topRight);
|
||||||
|
@ -260,7 +276,7 @@ Ref<ResultPoint> Detector::correctTopRightRectangular(Ref<ResultPoint> bottomLef
|
||||||
sin = (topRight->getY() - bottomRight->getY()) / norm;
|
sin = (topRight->getY() - bottomRight->getY()) / norm;
|
||||||
|
|
||||||
Ref<ResultPoint> c2(
|
Ref<ResultPoint> c2(
|
||||||
new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin));
|
new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin));
|
||||||
|
|
||||||
if (!isValid(c1)) {
|
if (!isValid(c1)) {
|
||||||
if (isValid(c2)) {
|
if (isValid(c2)) {
|
||||||
|
@ -273,9 +289,9 @@ Ref<ResultPoint> Detector::correctTopRightRectangular(Ref<ResultPoint> bottomLef
|
||||||
}
|
}
|
||||||
|
|
||||||
int l1 = abs(dimensionTop - transitionsBetween(topLeft, c1)->getTransitions())
|
int l1 = abs(dimensionTop - transitionsBetween(topLeft, c1)->getTransitions())
|
||||||
+ abs(dimensionRight - transitionsBetween(bottomRight, c1)->getTransitions());
|
+ abs(dimensionRight - transitionsBetween(bottomRight, c1)->getTransitions());
|
||||||
int l2 = abs(dimensionTop - transitionsBetween(topLeft, c2)->getTransitions())
|
int l2 = abs(dimensionTop - transitionsBetween(topLeft, c2)->getTransitions())
|
||||||
+ abs(dimensionRight - transitionsBetween(bottomRight, c2)->getTransitions());
|
+ abs(dimensionRight - transitionsBetween(bottomRight, c2)->getTransitions());
|
||||||
|
|
||||||
return l1 <= l2 ? c1 : c2;
|
return l1 <= l2 ? c1 : c2;
|
||||||
}
|
}
|
||||||
|
@ -285,8 +301,8 @@ Ref<ResultPoint> Detector::correctTopRightRectangular(Ref<ResultPoint> bottomLef
|
||||||
* for a square matrix
|
* for a square matrix
|
||||||
*/
|
*/
|
||||||
Ref<ResultPoint> Detector::correctTopRight(Ref<ResultPoint> bottomLeft,
|
Ref<ResultPoint> Detector::correctTopRight(Ref<ResultPoint> bottomLeft,
|
||||||
Ref<ResultPoint> bottomRight, Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight,
|
Ref<ResultPoint> bottomRight, Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight,
|
||||||
int dimension) {
|
int dimension) {
|
||||||
|
|
||||||
float corr = distance(bottomLeft, bottomRight) / (float) dimension;
|
float corr = distance(bottomLeft, bottomRight) / (float) dimension;
|
||||||
int norm = distance(topLeft, topRight);
|
int norm = distance(topLeft, topRight);
|
||||||
|
@ -294,7 +310,7 @@ Ref<ResultPoint> Detector::correctTopRight(Ref<ResultPoint> bottomLeft,
|
||||||
float sin = (topRight->getY() - topLeft->getY()) / norm;
|
float sin = (topRight->getY() - topLeft->getY()) / norm;
|
||||||
|
|
||||||
Ref<ResultPoint> c1(
|
Ref<ResultPoint> c1(
|
||||||
new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin));
|
new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin));
|
||||||
|
|
||||||
corr = distance(bottomLeft, topLeft) / (float) dimension;
|
corr = distance(bottomLeft, topLeft) / (float) dimension;
|
||||||
norm = distance(bottomRight, topRight);
|
norm = distance(bottomRight, topRight);
|
||||||
|
@ -302,7 +318,7 @@ Ref<ResultPoint> Detector::correctTopRight(Ref<ResultPoint> bottomLeft,
|
||||||
sin = (topRight->getY() - bottomRight->getY()) / norm;
|
sin = (topRight->getY() - bottomRight->getY()) / norm;
|
||||||
|
|
||||||
Ref<ResultPoint> c2(
|
Ref<ResultPoint> c2(
|
||||||
new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin));
|
new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin));
|
||||||
|
|
||||||
if (!isValid(c1)) {
|
if (!isValid(c1)) {
|
||||||
if (isValid(c2)) {
|
if (isValid(c2)) {
|
||||||
|
@ -315,18 +331,18 @@ Ref<ResultPoint> Detector::correctTopRight(Ref<ResultPoint> bottomLeft,
|
||||||
}
|
}
|
||||||
|
|
||||||
int l1 = abs(
|
int l1 = abs(
|
||||||
transitionsBetween(topLeft, c1)->getTransitions()
|
transitionsBetween(topLeft, c1)->getTransitions()
|
||||||
- transitionsBetween(bottomRight, c1)->getTransitions());
|
- transitionsBetween(bottomRight, c1)->getTransitions());
|
||||||
int l2 = abs(
|
int l2 = abs(
|
||||||
transitionsBetween(topLeft, c2)->getTransitions()
|
transitionsBetween(topLeft, c2)->getTransitions()
|
||||||
- transitionsBetween(bottomRight, c2)->getTransitions());
|
- transitionsBetween(bottomRight, c2)->getTransitions());
|
||||||
|
|
||||||
return l1 <= l2 ? c1 : c2;
|
return l1 <= l2 ? c1 : c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Detector::isValid(Ref<ResultPoint> p) {
|
bool Detector::isValid(Ref<ResultPoint> p) {
|
||||||
return p->getX() >= 0 && p->getX() < image_->getWidth() && p->getY() > 0
|
return p->getX() >= 0 && p->getX() < image_->getWidth() && p->getY() > 0
|
||||||
&& p->getY() < image_->getHeight();
|
&& p->getY() < image_->getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Detector::distance(Ref<ResultPoint> a, Ref<ResultPoint> b) {
|
int Detector::distance(Ref<ResultPoint> a, Ref<ResultPoint> b) {
|
||||||
|
@ -334,7 +350,7 @@ int Detector::distance(Ref<ResultPoint> a, Ref<ResultPoint> b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<ResultPointsAndTransitions> Detector::transitionsBetween(Ref<ResultPoint> from,
|
Ref<ResultPointsAndTransitions> Detector::transitionsBetween(Ref<ResultPoint> from,
|
||||||
Ref<ResultPoint> to) {
|
Ref<ResultPoint> to) {
|
||||||
// See QR Code Detector, sizeOfBlackWhiteBlackRun()
|
// See QR Code Detector, sizeOfBlackWhiteBlackRun()
|
||||||
int fromX = (int) from->getX();
|
int fromX = (int) from->getX();
|
||||||
int fromY = (int) from->getY();
|
int fromY = (int) from->getY();
|
||||||
|
@ -377,32 +393,32 @@ Ref<ResultPointsAndTransitions> Detector::transitionsBetween(Ref<ResultPoint> fr
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<PerspectiveTransform> Detector::createTransform(Ref<ResultPoint> topLeft,
|
Ref<PerspectiveTransform> Detector::createTransform(Ref<ResultPoint> topLeft,
|
||||||
Ref<ResultPoint> topRight, Ref<ResultPoint> bottomLeft, Ref<ResultPoint> bottomRight,
|
Ref<ResultPoint> topRight, Ref<ResultPoint> bottomLeft, Ref<ResultPoint> bottomRight,
|
||||||
int dimensionX, int dimensionY) {
|
int dimensionX, int dimensionY) {
|
||||||
|
|
||||||
Ref<PerspectiveTransform> transform(
|
Ref<PerspectiveTransform> transform(
|
||||||
PerspectiveTransform::quadrilateralToQuadrilateral(
|
PerspectiveTransform::quadrilateralToQuadrilateral(
|
||||||
0.5f,
|
0.5f,
|
||||||
0.5f,
|
0.5f,
|
||||||
dimensionX - 0.5f,
|
dimensionX - 0.5f,
|
||||||
0.5f,
|
0.5f,
|
||||||
dimensionX - 0.5f,
|
dimensionX - 0.5f,
|
||||||
dimensionY - 0.5f,
|
dimensionY - 0.5f,
|
||||||
0.5f,
|
0.5f,
|
||||||
dimensionY - 0.5f,
|
dimensionY - 0.5f,
|
||||||
topLeft->getX(),
|
topLeft->getX(),
|
||||||
topLeft->getY(),
|
topLeft->getY(),
|
||||||
topRight->getX(),
|
topRight->getX(),
|
||||||
topRight->getY(),
|
topRight->getY(),
|
||||||
bottomRight->getX(),
|
bottomRight->getX(),
|
||||||
bottomRight->getY(),
|
bottomRight->getY(),
|
||||||
bottomLeft->getX(),
|
bottomLeft->getX(),
|
||||||
bottomLeft->getY()));
|
bottomLeft->getY()));
|
||||||
return transform;
|
return transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<BitMatrix> Detector::sampleGrid(Ref<BitMatrix> image, int dimensionX, int dimensionY,
|
Ref<BitMatrix> Detector::sampleGrid(Ref<BitMatrix> image, int dimensionX, int dimensionY,
|
||||||
Ref<PerspectiveTransform> transform) {
|
Ref<PerspectiveTransform> transform) {
|
||||||
GridSampler &sampler = GridSampler::getInstance();
|
GridSampler &sampler = GridSampler::getInstance();
|
||||||
return sampler.sampleGrid(image, dimensionX, dimensionY, transform);
|
return sampler.sampleGrid(image, dimensionX, dimensionY, transform);
|
||||||
}
|
}
|
||||||
|
@ -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