Пример #1
0
  /** Decodes a symbol given any point (cx, cy) inside the center circle (bulls-eye) of the code. */
  public int decode(Scanner scanner, int cx, int cy) {

    int up =
        (scanner.ydist(cx, cy, -1) + scanner.ydist(cx - 1, cy, -1) + scanner.ydist(cx + 1, cy, -1));

    int down =
        (scanner.ydist(cx, cy, 1) + scanner.ydist(cx - 1, cy, 1) + scanner.ydist(cx + 1, cy, 1));

    int left =
        (scanner.xdist(cx, cy, -1) + scanner.xdist(cx, cy - 1, -1) + scanner.xdist(cx, cy + 1, -1));

    int right =
        (scanner.xdist(cx, cy, 1) + scanner.xdist(cx, cy - 1, 1) + scanner.xdist(cx, cy + 1, 1));

    this.x = cx;
    this.y = cy;
    this.x += (right - left) / 6.0f;
    this.y += (down - up) / 6.0f;
    this.unit = readUnit(scanner);
    this.code = -1;
    if (unit < 0) return -1;

    int c = 0;
    int maxc = 0;
    float arca;
    float maxa = 0;
    float maxu = 0;

    // -----------------------------------------
    // Try different unit and arc adjustments,
    // save the one that produces a maximum
    // confidence reading...
    // -----------------------------------------
    for (int u = -2; u <= 2; u++) {
      for (int a = 0; a < 10; a++) {
        arca = a * ARC * 0.1f;
        c = readCode(scanner, unit + (unit * 0.05f * u), arca);
        if (c > maxc) {
          maxc = c;
          maxa = arca;
          maxu = unit + (unit * 0.05f * u);
        }
      }
    }

    // One last call to readCode to reset orientation and code
    if (maxc > 0) {
      unit = maxu;
      readCode(scanner, unit, maxa);
      this.code = rotateLowest(code, maxa);
    }

    return this.code;
  }