-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTess4JTest.java
More file actions
55 lines (45 loc) · 1.55 KB
/
Tess4JTest.java
File metadata and controls
55 lines (45 loc) · 1.55 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
package imghand;
import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import net.sourceforge.tess4j.util.LoadLibs;
import java.io.File;
import java.io.IOException;
/**
* @author mood321
* @date 2020/5/13 21:28
* @email [email protected]
*/
public class Tess4JTest {
public static void main(String[] args){
String path = "D://tem"; //我的图片路径
File file = new File(path + "//tt3.jpg");
ITesseract instance = new Tesseract();
/**
* 获取项目根路径,例如: D:
*/
File directory = new File(path);
String courseFile = null;
try {
courseFile = directory.getCanonicalPath();
} catch (IOException e) {
e.printStackTrace();
}
//设置训练库的位置
String s = Tess4JTest.class.getResource("/").getPath().replaceFirst("/","") + "tessdata";
System.out.println(s);
instance.setDatapath(s);
instance.setLanguage("eng");//chi_sim :简体中文, eng 根据需求选择语言库
String result = null;
try {
long startTime = System.currentTimeMillis();
result = instance.doOCR(file);
long endTime = System.currentTimeMillis();
System.out.println("Time is:" + (endTime - startTime) + " 毫秒");
} catch (TesseractException e) {
e.printStackTrace();
}
System.out.println("result: ");
System.out.println(result);
}
}