
z11.decaptcha.DecaptcherSimpleCompare Maven / Gradle / Ivy
package z11.decaptcha;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import javax.imageio.ImageIO;
public class DecaptcherSimpleCompare {
ArrayList words;
public DecaptcherSimpleCompare() {
this.words = new ArrayList();
}
public void inportDictionary(String path) {
for (String file : z11.F_ile.listFileInfolder(path)) {
try {
if (!path.endsWith("/")) {
path = path + "/";
}
BufferedImage image = z11.I_mage.readImage(path + file);
this.words.add(new Word(image, "" + file.charAt(0)));
} catch (Exception ex) {
}
}
}
private boolean inner(int[][] mt1, int h1, int w1, int[][] mt2, int h2, int w2, int i0, int j0, String w) {
if ((h1 < h2 + i0) || (w1 < w2 + j0)) {
return false;
}
for (int i = i0; i < h2 + i0; i++) {
for (int j = j0; j < w2 + j0; j++) {
if ((mt1[i][j] == 0) && (mt2[(i - i0)][(j - j0)] == 1)) {
return false;
}
}
}
return true;
}
public String resolve(String path) {
try {
String ret = "";
BufferedImage captImage = ImageIO.read(new File(path));
IMG img1 = new IMG(captImage);
for (int j = 0; j < img1.w; j++) {
for (int i = 0; i < img1.h; i++) {
for (int t = 0; t < this.words.size(); t++) {
if (inner(img1.mt, img1.h, img1.w, ((Word) this.words.get(t)).imgw.mt, ((Word) this.words.get(t)).imgw.h, ((Word) this.words.get(t)).imgw.w, i, j, ((Word) this.words.get(t)).w)) {
ret = ret + ((Word) this.words.get(t)).w;
j += ((Word) this.words.get(t)).imgw.w / 2;
i = 0;
t = -1;
}
}
}
}
return ret;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
public static void main(String[] sfsfsdf) {
DecaptcherSimpleCompare theDecaptchar = new DecaptcherSimpleCompare();
theDecaptchar.inportDictionary("D:\\bitbucket\\viettel-dktt-2017\\viettel-dktt-2017\\src\\main\\resources\\word");
for (int i = 1; i <= 200; i++) {
String capt = theDecaptchar.resolve("D:\\bitbucket\\viettel-dktt-2017\\viettel-dktt-2017\\capcha\\register\\" + i + ".png");
System.out.println(i + " capt:" + capt.trim());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy