-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.java
More file actions
64 lines (52 loc) · 1.3 KB
/
Example.java
File metadata and controls
64 lines (52 loc) · 1.3 KB
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
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import javax.imageio.ImageIO;
public class Example
{
public static void main( String[] argz )
{
CRBCaptchaCrack.initClassifier();
int rv;
int i, j;
if ( argz.length != 1 ) {
System.out.printf( "Usage: Example <Input Image File>\n" );
return;
}
// ----------------- Read the File ----------------
String fname = argz[0];
FileInputStream fis;
File fi;
try {
fi = new File( fname );
fis = new FileInputStream( fi );
} catch( Exception e ) {
e.printStackTrace();
return;
}
byte[] data = new byte[(int)fi.length()];
int off = 0;
int nr = 0;
try {
while ( (off<data.length) && ( (nr=fis.read(data, off, data.length-off)) >= 0 ) ) {
off += nr;
}
fis.close();
} catch ( Exception e ) {
e.printStackTrace();
return;
}
// ---------------- Decode Image ------------------
CRBCaptchaCrack cc = new CRBCaptchaCrack();
rv = cc.decodeImage(data);
if ( rv < 0 ) {
System.out.printf( "Failure to read image!\n" );
}
cc.normalize();
// ------------ Partition and Normalize -----------
cc.partition();
cc.classify();
// ----------------- Output Result ------------------
System.out.printf( "Result: %s; Score: %d\n", cc.ptRes, cc.rscore );
};
};