Exemple #1
0
  public static Letter[] getLetters(Captcha captcha) throws InterruptedException {
    BackGroundImageManager bgit = new BackGroundImageManager(captcha);
    bgit.clearCaptchaAll();
    // clearlines(captcha);
    // clearlines(captcha);

    toBlack(captcha);
    fill(captcha, 1, 9);

    PixelObject[] os = getObjects(captcha);
    // for (PixelObject pixelObject : os) {
    // BasicWindow.showImage(pixelObject.toLetter().getImage());

    // }
    captcha.reset();
    Letter[] lets = new Letter[os.length];
    for (int i = 0; i < lets.length; i++) {
      lets[i] = os[i].toLetter();
      int[] l = lets[i].getLocation();
      for (int x = 0; x < lets[i].getWidth(); x++) {
        for (int y = 0; y < lets[i].getHeight(); y++) {
          lets[i].grid[x][y] = captcha.getPixelValue(x + l[0] - 1, y + l[1] - 1);
        }
      }
      // blurIt(lets[i], 3);
      toBlack(lets[i]);
      lets[i].resizetoHeight(30);
      // BasicWindow.showImage(lets[i].getImage());

    } //
    // BasicWindow.showImage(captcha.getImage());

    return lets;
  }
 /**
  * Erzeugt ein zufallsCaptcha aus dem Captchaordner
  *
  * @return
  */
 public Captcha getRandomCaptcha() {
   Captcha captchaImage =
       this.getJac().createCaptcha(Utilities.loadImage(this.getRandomCaptchaFile()));
   if (captchaImage != null && captchaImage.getWidth() > 0 && captchaImage.getWidth() > 0) {
     return captchaImage;
   }
   captchaImage = this.getJac().createCaptcha(Utilities.loadImage(this.getRandomCaptchaFile()));
   if (captchaImage != null && captchaImage.getWidth() > 0 && captchaImage.getWidth() > 0) {
     return captchaImage;
   }
   return null;
 }
Exemple #3
0
 private int checkBackground(int x, int y, PixelObject n) {
   int c = captcha.getPixelValue(x, y);
   boolean b = isBackground(c);
   if (!b) {
     n.add(x, y, c);
   }
   return b ? 1 : 0;
 }
Exemple #4
0
 private static PixelObject[] getObjects(Captcha captcha) {
   int startX = 1;
   outer:
   for (; startX < captcha.getWidth(); startX++) {
     for (int y = 1; y < captcha.getHeight() - 1; y++) {
       if (captcha.grid[startX][y] != 0xffffff) break outer;
     }
   }
   int xEnd = captcha.getWidth() - 2;
   outer:
   for (; xEnd > 0; xEnd--) {
     for (int y = 1; y < captcha.getHeight() - 1; y++) {
       if (captcha.grid[xEnd][y] != 0xffffff) break outer;
     }
   }
   int wi = (xEnd - startX) / 6;
   PixelObject[] ret = new PixelObject[6];
   for (int i = 0; i < ret.length; i++) {
     ret[i] = new PixelObject(captcha);
   }
   int add = 3;
   for (int x = startX; x < startX + wi + add; x++) {
     for (int y = 0; y < captcha.getHeight(); y++) {
       if (captcha.grid[x][y] != 0xffffff) {
         ret[0].add(x, y, captcha.grid[x][y]);
       }
     }
   }
   for (int x = startX + wi; x < startX + wi * 2 + add; x++) {
     for (int y = 0; y < captcha.getHeight(); y++) {
       if (captcha.grid[x][y] != 0xffffff) {
         ret[1].add(x, y, captcha.grid[x][y]);
       }
     }
   }
   for (int x = startX + wi * 2; x < startX + wi * 3 + add; x++) {
     for (int y = 0; y < captcha.getHeight(); y++) {
       if (captcha.grid[x][y] != 0xffffff) {
         ret[2].add(x, y, captcha.grid[x][y]);
       }
     }
   }
   for (int x = startX + wi * 3; x < startX + wi * 4 + add; x++) {
     for (int y = 0; y < captcha.getHeight(); y++) {
       if (captcha.grid[x][y] != 0xffffff) {
         ret[3].add(x, y, captcha.grid[x][y]);
       }
     }
   }
   for (int x = startX + wi * 4; x < startX + wi * 5 + add; x++) {
     for (int y = 0; y < captcha.getHeight(); y++) {
       if (captcha.grid[x][y] != 0xffffff) {
         ret[4].add(x, y, captcha.grid[x][y]);
       }
     }
   }
   for (int x = startX + wi * 5; x < startX + wi * 6 + add; x++) {
     for (int y = 0; y < captcha.getHeight(); y++) {
       if (captcha.grid[x][y] != 0xffffff) {
         ret[5].add(x, y, captcha.grid[x][y]);
       }
     }
   }
   return ret;
 }