c++ port of r2660

git-svn-id: https://zxing.googlecode.com/svn/trunk@2665 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
smparkes@smparkes.net 2013-04-21 02:48:05 +00:00
parent 28751276f3
commit ce8f339509
2 changed files with 50 additions and 47 deletions

View file

@ -140,26 +140,26 @@ ArrayRef< Ref<ResultPoint> >
Detector::getMatrixCornerPoints(std::vector<Ref<Point> > bullEyeCornerPoints) {
float ratio = (2 * nbLayers_ + (nbLayers_ > 4 ? 1 : 0) + (nbLayers_ - 4) / 8) / (2.0f * nbCenterLayers_);
int dx = bullEyeCornerPoints[0]->x - bullEyeCornerPoints[2]->x;
int dx = bullEyeCornerPoints[0]->getX() - bullEyeCornerPoints[2]->getX();
dx += dx > 0 ? 1 : -1;
int dy = bullEyeCornerPoints[0]->y - bullEyeCornerPoints[2]->y;
int dy = bullEyeCornerPoints[0]->getY() - bullEyeCornerPoints[2]->getY();
dy += dy > 0 ? 1 : -1;
int targetcx = math_utils::round(bullEyeCornerPoints[2]->x - ratio * dx);
int targetcy = math_utils::round(bullEyeCornerPoints[2]->y - ratio * dy);
int targetcx = math_utils::round(bullEyeCornerPoints[2]->getX() - ratio * dx);
int targetcy = math_utils::round(bullEyeCornerPoints[2]->getY() - ratio * dy);
int targetax = math_utils::round(bullEyeCornerPoints[0]->x + ratio * dx);
int targetay = math_utils::round(bullEyeCornerPoints[0]->y + ratio * dy);
int targetax = math_utils::round(bullEyeCornerPoints[0]->getX() + ratio * dx);
int targetay = math_utils::round(bullEyeCornerPoints[0]->getY() + ratio * dy);
dx = bullEyeCornerPoints[1]->x - bullEyeCornerPoints[3]->x;
dx = bullEyeCornerPoints[1]->getX() - bullEyeCornerPoints[3]->getX();
dx += dx > 0 ? 1 : -1;
dy = bullEyeCornerPoints[1]->y - bullEyeCornerPoints[3]->y;
dy = bullEyeCornerPoints[1]->getY() - bullEyeCornerPoints[3]->getY();
dy += dy > 0 ? 1 : -1;
int targetdx = math_utils::round(bullEyeCornerPoints[3]->x - ratio * dx);
int targetdy = math_utils::round(bullEyeCornerPoints[3]->y - ratio * dy);
int targetbx = math_utils::round(bullEyeCornerPoints[1]->x + ratio * dx);
int targetby = math_utils::round(bullEyeCornerPoints[1]->y + ratio * dy);
int targetdx = math_utils::round(bullEyeCornerPoints[3]->getX() - ratio * dx);
int targetdy = math_utils::round(bullEyeCornerPoints[3]->getY() - ratio * dy);
int targetbx = math_utils::round(bullEyeCornerPoints[1]->getX() + ratio * dx);
int targetby = math_utils::round(bullEyeCornerPoints[1]->getY() + ratio * dy);
if (!isValid(targetax, targetay) ||
!isValid(targetbx, targetby) ||
@ -269,21 +269,21 @@ std::vector<Ref<Point> > Detector::getBullEyeCornerPoints(Ref<zxing::aztec::Poin
float ratio = 0.75f*2 / (2*nbCenterLayers_-3);
int dx = pina->x - pind->x;
int dy = pina->y - pinc->y;
int dx = pina->getX() - pind->getX();
int dy = pina->getY() - pinc->getY();
int targetcx = math_utils::round(pinc->x - ratio * dx);
int targetcy = math_utils::round(pinc->y - ratio * dy);
int targetax = math_utils::round(pina->x + ratio * dx);
int targetay = math_utils::round(pina->y + ratio * dy);
int targetcx = math_utils::round(pinc->getX() - ratio * dx);
int targetcy = math_utils::round(pinc->getY() - ratio * dy);
int targetax = math_utils::round(pina->getX() + ratio * dx);
int targetay = math_utils::round(pina->getY() + ratio * dy);
dx = pinb->x - pind->x;
dy = pinb->y - pind->y;
dx = pinb->getX() - pind->getX();
dy = pinb->getY() - pind->getY();
int targetdx = math_utils::round(pind->x - ratio * dx);
int targetdy = math_utils::round(pind->y - ratio * dy);
int targetbx = math_utils::round(pinb->x + ratio * dx);
int targetby = math_utils::round(pinb->y + ratio * dy);
int targetdx = math_utils::round(pind->getX() - ratio * dx);
int targetdy = math_utils::round(pind->getY() - ratio * dy);
int targetbx = math_utils::round(pinb->getX() + ratio * dx);
int targetby = math_utils::round(pinb->getY() + ratio * dy);
if (!isValid(targetax, targetay) ||
!isValid(targetbx, targetby) ||
@ -429,11 +429,11 @@ Ref<BitArray> Detector::sampleLine(Ref<zxing::aztec::Point> p1, Ref<zxing::aztec
float d = distance(p1, p2);
float moduleSize = d / (size-1);
float dx = moduleSize * float(p2->x - p1->x)/d;
float dy = moduleSize * float(p2->y - p1->y)/d;
float dx = moduleSize * float(p2->getX() - p1->getX())/d;
float dy = moduleSize * float(p2->getY() - p1->getY())/d;
float px = float(p1->x);
float py = float(p1->y);
float px = float(p1->getX());
float py = float(p1->getY());
for (int i = 0; i < size; i++) {
if (image_->get(math_utils::round(px), math_utils::round(py))) res->set(i);
@ -450,10 +450,10 @@ bool Detector::isWhiteOrBlackRectangle(Ref<zxing::aztec::Point> p1,
Ref<zxing::aztec::Point> p4) {
int corr = 3;
p1 = new Point(p1->x - corr, p1->y + corr);
p2 = new Point(p2->x - corr, p2->y - corr);
p3 = new Point(p3->x + corr, p3->y - corr);
p4 = new Point(p4->x + corr, p4->y + corr);
p1 = new Point(p1->getX() - corr, p1->getY() + corr);
p2 = new Point(p2->getX() - corr, p2->getY() - corr);
p3 = new Point(p3->getX() + corr, p3->getY() - corr);
p4 = new Point(p4->getX() + corr, p4->getY() + corr);
int cInit = getColor(p4, p1);
@ -485,15 +485,15 @@ bool Detector::isWhiteOrBlackRectangle(Ref<zxing::aztec::Point> p1,
int Detector::getColor(Ref<zxing::aztec::Point> p1, Ref<zxing::aztec::Point> p2) {
float d = distance(p1, p2);
float dx = (p2->x - p1->x) / d;
float dy = (p2->y - p1->y) / d;
float dx = (p2->getX() - p1->getX()) / d;
float dy = (p2->getY() - p1->getY()) / d;
int error = 0;
float px = float(p1->x);
float py = float(p1->y);
float px = float(p1->getX());
float py = float(p1->getY());
bool colorModel = image_->get(p1->x, p1->y);
bool colorModel = image_->get(p1->getX(), p1->getY());
for (int i = 0; i < d; i++) {
px += dx;
@ -514,8 +514,8 @@ int Detector::getColor(Ref<zxing::aztec::Point> p1, Ref<zxing::aztec::Point> p2)
}
Ref<Point> Detector::getFirstDifferent(Ref<zxing::aztec::Point> init, bool color, int dx, int dy) {
int x = init->x + dx;
int y = init->y + dy;
int x = init->getX() + dx;
int y = init->getY() + dy;
while (isValid(x, y) && image_->get(x, y) == color) {
x += dx;
@ -545,5 +545,5 @@ bool Detector::isValid(int x, int y) {
}
float Detector::distance(Ref<zxing::aztec::Point> a, Ref<zxing::aztec::Point> b) {
return sqrtf((float)((a->x - b->x) * (a->x - b->x) + (a->y - b->y) * (a->y - b->y)));
return sqrtf((float)((a->getX() - b->getX()) * (a->getX() - b->getX()) + (a->getY() - b->getY()) * (a->getY() - b->getY())));
}

View file

@ -34,21 +34,24 @@ namespace zxing {
namespace aztec {
class Point : public Counted {
public:
int x;
int y;
private:
const int x;
const int y;
public:
Ref<ResultPoint> toResultPoint() {
return Ref<ResultPoint>(new ResultPoint(float(x), float(y)));
}
Point(int ax, int ay):x(ax),y(ay) {};
Point(int ax, int ay) : x(ax), y(ay) {}
int getX() const { return x; }
int getY() const { return y; }
};
class Detector : public Counted {
private:
private:
Ref<BitMatrix> image_;
bool compact_;
@ -78,7 +81,7 @@ private:
bool isValid(int x, int y);
static float distance(Ref<Point> a, Ref<Point> b);
public:
public:
Detector(Ref<BitMatrix> image);
Ref<AztecDetectorResult> detect();
};