示例#1
0
 static void toBlack(PixelGrid captcha) {
   for (int x = 0; x < captcha.getWidth(); x++) {
     for (int y = 0; y < captcha.getHeight(); y++) {
       if (captcha.grid[x][y] != 0xffffff && captcha.grid[x][y] != 0xff0000) {
         captcha.grid[x][y] = 0x000000;
       } else captcha.grid[x][y] = 0xffffff;
     }
   }
 }
示例#2
0
  static void follow(int x0, int y0, PixelGrid px, PixelGrid captcha, double dmin, double dmax) {
    px.grid[x0][y0] = 0x000000;

    int x = Math.max(0, x0 - 1);
    int y = Math.max(0, y0 - 1);
    for (x0 = x; x0 < Math.min(x + 2, captcha.getWidth()); x0++) {
      for (y0 = y; y0 < Math.min(y + 2, captcha.getHeight()); y0++) {
        if (px.grid[x0][y0] == 0xffffff) {
          px.grid[x0][y0] = 0x000000;
          // follow(x0, y0, px, captcha, dmin, dmax);
        }
      }
    }
  }
示例#3
0
  static void fill(PixelGrid captcha, double dmin, double dmax) {

    PixelGrid px = new PixelGrid(captcha.getWidth(), captcha.getHeight());
    px.grid = new int[captcha.getWidth()][captcha.getHeight()];
    for (int x = 0; x < captcha.getWidth(); x++) {
      for (int y = 0; y < captcha.getHeight(); y++) {
        px.grid[x][y] = 0xffffff;
      }
    }
    for (int x = 0; x < captcha.getWidth(); x++) {
      for (int y = 0; y < captcha.getHeight(); y++) {
        if (px.grid[x][y] == 0xffffff && captcha.grid[x][y] != 0xffffff) {

          for (int x1 = x; x1 < Math.min(x + dmax, captcha.getWidth()); x1++) {
            for (int y1 = y; y1 < Math.min(y + dmax, captcha.getHeight()); y1++) {
              if (px.grid[x1][y1] == 0xffffff && captcha.grid[x1][y1] != 0xffffff) {
                double xd = (x1 - x);
                double yd = (y1 - y);
                double diff = Math.sqrt(xd * xd + yd * yd);

                if (diff > dmin && diff < dmax) {
                  if (checkLine(x, x1, y, y1, captcha, 0xffffff)) {

                    int xadd;
                    int yadd;
                    int x1add;
                    int y1add;
                    int di = 3;
                    if (xd == 0) {
                      xadd = 0;
                      yadd = di;
                      x1add = 0;
                      y1add = di - 1;
                    } else if (yd == 0) {
                      xadd = di;
                      x1add = di - 1;
                      y1add = 0;
                      yadd = 0;
                    } else {
                      double m = yd / xd;
                      xadd = (int) Math.floor((1 - m) * di);
                      yadd = (int) Math.floor(m * di);
                      x1add = (int) Math.ceil((1 - m) * (di - 1));
                      y1add = (int) Math.floor(m * (di - 1));
                    }
                    // follow((x1-x)/2+x,(y1-y)/2+y, px,
                    // captcha, dmin, dmax);
                    int f = y - yadd;
                    int fx = x - xadd;
                    if (f > 0
                        && fx > 0
                        && f < captcha.getHeight()
                        && fx < captcha.getWidth()
                        && captcha.grid[fx][f] != 0xffffff) {
                      try {
                        if (checkLine(x, x - x1add, y, y - y1add, captcha, 0x000000)) {
                          f = y1 + yadd;
                          fx = x1 + xadd;
                          if (f > 0
                              && fx > 0
                              && f < captcha.getHeight()
                              && fx < captcha.getWidth()
                              && captcha.grid[fx][f] != 0xffffff
                              && checkLine(x1, x1 + x1add, y1, y1 + y1add, captcha, 0x000000)) {
                            follow(x, y, px, captcha, dmin, dmax);
                            follow(x1, y1, px, captcha, dmin, dmax);
                          }
                        }
                      } catch (Exception e) {
                        px.grid[x][y] = captcha.grid[x][y];
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    for (int x = 0; x < captcha.getWidth(); x++) {
      for (int y = 0; y < captcha.getHeight(); y++) {
        if (captcha.grid[x][y] == 0xffffff) {
          px.grid[x][y] = 0xffffff;
        }
      }
    }
    captcha.grid = px.grid;
  }