mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Issue 505
git-svn-id: https://zxing.googlecode.com/svn/trunk@1524 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
0a6cac9820
commit
00322f3873
|
@ -100,4 +100,12 @@ bool DecodeHints::getTryHarder() const {
|
|||
return (hints & TRYHARDER_HINT);
|
||||
}
|
||||
|
||||
void DecodeHints::setResultPointCallback(Ref<ResultPointCallback> const& _callback) {
|
||||
callback = _callback;
|
||||
}
|
||||
|
||||
Ref<ResultPointCallback> DecodeHints::getResultPointCallback() const {
|
||||
return callback;
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
|
||||
#include <zxing/BarcodeFormat.h>
|
||||
#include <zxing/ResultPointCallback.h>
|
||||
|
||||
namespace zxing {
|
||||
|
||||
|
@ -42,6 +43,8 @@ class DecodeHints {
|
|||
|
||||
DecodeHintType hints;
|
||||
|
||||
Ref<ResultPointCallback> callback;
|
||||
|
||||
public:
|
||||
|
||||
static const DecodeHints PRODUCT_HINT;
|
||||
|
@ -56,6 +59,9 @@ class DecodeHints {
|
|||
void setTryHarder(bool toset);
|
||||
bool getTryHarder() const;
|
||||
|
||||
void setResultPointCallback(Ref<ResultPointCallback> const&);
|
||||
Ref<ResultPointCallback> getResultPointCallback() const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -20,3 +20,8 @@
|
|||
|
||||
#include <zxing/ResultPoint.h>
|
||||
|
||||
namespace zxing {
|
||||
|
||||
ResultPoint::~ResultPoint() {}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ class ResultPoint : public Counted {
|
|||
protected:
|
||||
ResultPoint() {}
|
||||
public:
|
||||
virtual ~ResultPoint();
|
||||
|
||||
virtual float getX() const = 0;
|
||||
virtual float getY() const = 0;
|
||||
};
|
||||
|
|
27
cpp/core/src/zxing/ResultPointCallback.cpp
Normal file
27
cpp/core/src/zxing/ResultPointCallback.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* ResultPointCallback.cpp
|
||||
* zxing
|
||||
*
|
||||
* Created by Christian Brunschen on 13/05/2008.
|
||||
* Copyright 2008 ZXing authors All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <zxing/ResultPointCallback.h>
|
||||
|
||||
namespace zxing {
|
||||
|
||||
ResultPointCallback::~ResultPointCallback() {}
|
||||
|
||||
}
|
39
cpp/core/src/zxing/ResultPointCallback.h
Normal file
39
cpp/core/src/zxing/ResultPointCallback.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#ifndef __RESULT_POINT_CALLBACK_H__
|
||||
#define __RESULT_POINT_CALLBACK_H__
|
||||
|
||||
/*
|
||||
* ResultPointCallback.h
|
||||
* zxing
|
||||
*
|
||||
* Copyright 2010 ZXing authors All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <zxing/common/Counted.h>
|
||||
|
||||
namespace zxing {
|
||||
|
||||
class ResultPoint;
|
||||
|
||||
class ResultPointCallback : public Counted {
|
||||
protected:
|
||||
ResultPointCallback() {}
|
||||
public:
|
||||
virtual void foundPossibleResultPoint(ResultPoint const& point) = 0;
|
||||
virtual ~ResultPointCallback();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RESULT_POINT_CALLBACK_H__
|
|
@ -112,15 +112,19 @@ Ref<AlignmentPattern> AlignmentPatternFinder::handlePossibleCenter(vector<int> &
|
|||
// Hadn't found this before; save it
|
||||
tmp->retain();
|
||||
possibleCenters_->push_back(tmp);
|
||||
if (callback_ != 0) {
|
||||
callback_->foundPossibleResultPoint(*tmp);
|
||||
}
|
||||
}
|
||||
Ref<AlignmentPattern> result;
|
||||
return result;
|
||||
}
|
||||
|
||||
AlignmentPatternFinder::AlignmentPatternFinder(Ref<BitMatrix> image, size_t startX, size_t startY, size_t width,
|
||||
size_t height, float moduleSize) :
|
||||
size_t height, float moduleSize,
|
||||
Ref<ResultPointCallback>const& callback) :
|
||||
image_(image), possibleCenters_(new vector<AlignmentPattern *> ()), startX_(startX), startY_(startY),
|
||||
width_(width), height_(height), moduleSize_(moduleSize) {
|
||||
width_(width), height_(height), moduleSize_(moduleSize), callback_(callback) {
|
||||
}
|
||||
|
||||
AlignmentPatternFinder::~AlignmentPatternFinder() {
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "AlignmentPattern.h"
|
||||
#include <zxing/common/Counted.h>
|
||||
#include <zxing/common/BitMatrix.h>
|
||||
#include <zxing/ResultPointCallback.h>
|
||||
#include <vector>
|
||||
|
||||
namespace zxing {
|
||||
|
@ -51,7 +52,7 @@ private:
|
|||
|
||||
public:
|
||||
AlignmentPatternFinder(Ref<BitMatrix> image, size_t startX, size_t startY, size_t width, size_t height,
|
||||
float moduleSize);
|
||||
float moduleSize, Ref<ResultPointCallback>const& callback);
|
||||
~AlignmentPatternFinder();
|
||||
Ref<AlignmentPattern> find();
|
||||
|
||||
|
@ -59,6 +60,7 @@ private:
|
|||
AlignmentPatternFinder(const AlignmentPatternFinder&);
|
||||
AlignmentPatternFinder& operator =(const AlignmentPatternFinder&);
|
||||
|
||||
Ref<ResultPointCallback> callback_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,8 @@ Ref<BitMatrix> Detector::getImage() {
|
|||
}
|
||||
|
||||
Ref<DetectorResult> Detector::detect(DecodeHints const& hints) {
|
||||
FinderPatternFinder finder(image_);
|
||||
callback_ = hints.getResultPointCallback();
|
||||
FinderPatternFinder finder(image_, hints.getResultPointCallback());
|
||||
Ref<FinderPatternInfo> info(finder.find(hints));
|
||||
|
||||
Ref<FinderPattern> topLeft(info->getTopLeft());
|
||||
|
@ -271,7 +272,7 @@ Ref<AlignmentPattern> Detector::findAlignmentInRegion(float overallEstModuleSize
|
|||
int alignmentAreaBottomY = min((int)(image_->getHeight() - 1), estAlignmentY + allowance);
|
||||
|
||||
AlignmentPatternFinder alignmentFinder(image_, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX
|
||||
- alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize);
|
||||
- alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, callback_);
|
||||
return alignmentFinder.find();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <zxing/common/BitMatrix.h>
|
||||
#include <zxing/qrcode/detector/AlignmentPattern.h>
|
||||
#include <zxing/common/PerspectiveTransform.h>
|
||||
#include <zxing/ResultPointCallback.h>
|
||||
|
||||
namespace zxing {
|
||||
|
||||
|
@ -35,6 +36,7 @@ namespace qrcode {
|
|||
class Detector : public Counted {
|
||||
private:
|
||||
Ref<BitMatrix> image_;
|
||||
Ref<ResultPointCallback> callback_;
|
||||
|
||||
protected:
|
||||
Ref<BitMatrix> getImage();
|
||||
|
|
|
@ -236,6 +236,9 @@ bool FinderPatternFinder::handlePossibleCenter(int* stateCount, size_t i, size_t
|
|||
if (!found) {
|
||||
Ref<FinderPattern> newPattern(new FinderPattern(centerJ, centerI, estimatedModuleSize));
|
||||
possibleCenters_.push_back(newPattern);
|
||||
if (callback_ != 0) {
|
||||
callback_->foundPossibleResultPoint(*newPattern);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -384,8 +387,9 @@ float FinderPatternFinder::distance(Ref<ResultPoint> p1, Ref<ResultPoint> p2) {
|
|||
return (float)sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
|
||||
FinderPatternFinder::FinderPatternFinder(Ref<BitMatrix> image) :
|
||||
image_(image), possibleCenters_(), hasSkipped_(false) {
|
||||
FinderPatternFinder::FinderPatternFinder(Ref<BitMatrix> image,
|
||||
Ref<ResultPointCallback>const& callback) :
|
||||
image_(image), possibleCenters_(), hasSkipped_(false), callback_(callback) {
|
||||
}
|
||||
|
||||
Ref<FinderPatternInfo> FinderPatternFinder::find(DecodeHints const& hints) {
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <zxing/qrcode/detector/FinderPatternInfo.h>
|
||||
#include <zxing/common/Counted.h>
|
||||
#include <zxing/common/BitMatrix.h>
|
||||
#include <zxing/ResultPointCallback.h>
|
||||
#include <vector>
|
||||
|
||||
namespace zxing {
|
||||
|
@ -42,6 +43,8 @@ private:
|
|||
std::vector<Ref<FinderPattern> > possibleCenters_;
|
||||
bool hasSkipped_;
|
||||
|
||||
Ref<ResultPointCallback> callback_;
|
||||
|
||||
/** stateCount must be int[5] */
|
||||
static float centerFromEnd(int* stateCount, int end);
|
||||
static bool foundPatternCross(int* stateCount);
|
||||
|
@ -55,10 +58,9 @@ private:
|
|||
bool haveMultiplyConfirmedCenters();
|
||||
std::vector<Ref<FinderPattern> > selectBestPatterns();
|
||||
static std::vector<Ref<FinderPattern> > orderBestPatterns(std::vector<Ref<FinderPattern> > patterns);
|
||||
|
||||
public:
|
||||
static float distance(Ref<ResultPoint> p1, Ref<ResultPoint> p2);
|
||||
FinderPatternFinder(Ref<BitMatrix> image);
|
||||
FinderPatternFinder(Ref<BitMatrix> image, Ref<ResultPointCallback>const&);
|
||||
Ref<FinderPatternInfo> find(DecodeHints const& hints);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue