parent
b29eb5da83
commit
da0a50032f
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>xyz.wbsite</groupId>
|
||||||
|
<artifactId>wbocr</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.sourceforge.tess4j</groupId>
|
||||||
|
<artifactId>tess4j</artifactId>
|
||||||
|
<version>4.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,33 @@
|
|||||||
|
package xyz.wbsite.ocr;
|
||||||
|
|
||||||
|
import net.sourceforge.tess4j.ITesseract;
|
||||||
|
import net.sourceforge.tess4j.Tesseract;
|
||||||
|
import net.sourceforge.tess4j.TesseractException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class Ocr {
|
||||||
|
|
||||||
|
public static void main(String[] args){
|
||||||
|
|
||||||
|
ITesseract instance = new Tesseract();
|
||||||
|
//如果未将tessdata放在根目录下需要指定绝对路径
|
||||||
|
instance.setDatapath("E:\\workspace\\wbocr\\src\\main\\resources\\tessdata");
|
||||||
|
|
||||||
|
//如果需要识别英文之外的语种,需要指定识别语种,并且需要将对应的语言包放进项目中
|
||||||
|
instance.setLanguage("chi_sim");
|
||||||
|
|
||||||
|
// 指定识别图片
|
||||||
|
File imgDir = new File("D:\\2018041914044684.png");
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
String ocrResult = null;
|
||||||
|
try {
|
||||||
|
ocrResult = instance.doOCR(imgDir);
|
||||||
|
} catch (TesseractException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 输出识别结果
|
||||||
|
System.out.println("OCR Result: \n" + ocrResult + "\n 耗时:" + (System.currentTimeMillis() - startTime) + "ms");
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue