forked from arunpatala/captcha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
73 lines (61 loc) · 1.95 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.awt.FlowLayout;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import nl.captcha.Captcha;
import nl.captcha.Captcha.Builder;
import nl.captcha.backgrounds.GradiatedBackgroundProducer;
import nl.captcha.gimpy.DropShadowGimpyRenderer;
import nl.captcha.gimpy.FishEyeGimpyRenderer;
import nl.captcha.noise.StraightLineNoiseProducer;
import nl.captcha.text.producer.ChineseTextProducer;
import nl.captcha.text.producer.DefaultTextProducer;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub // Required! Always!
//img2file("file.png",captcha.getImage());
img2ds("data/simpleRNN/",10000);
}
public static void img2ds(String dir, int N) throws IOException
{
List<String> ans = new LinkedList<String>();
PrintWriter out = new PrintWriter(dir+"/ans.txt");
for(int i=1;i<=N;i++)
{
if(i%100==0)System.out.println(i+","+N);
Captcha cap = new Captcha.Builder(200, 50)
.addText()
.addBackground()
.addNoise()
.gimp()
.addBackground(new GradiatedBackgroundProducer())
.addNoise(new StraightLineNoiseProducer())
.gimp(new FishEyeGimpyRenderer())
.build();
img2file(dir+"/"+i+".png",cap.getImage());
ans.add(cap.getAnswer());
out.println(cap.getAnswer());
}
//System.out.println(ans);
out.close();
}
public static void img2disp(BufferedImage img)
{
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(new JLabel(new ImageIcon(img)));
frame.pack();
frame.setVisible(true);
}
public static void img2file(String fileName, BufferedImage img) throws IOException
{
ImageIO.write(img, "png", new File(fileName));
}
}