Merge pull request #8831 from SmartyAnsh/BAEL-3874-OCR-with-Tesseract
BAEL-3874-ocr_with_tesseract
This commit is contained in:
commit
28d707bac8
|
@ -50,12 +50,24 @@
|
|||
<artifactId>imageio-bmp</artifactId>
|
||||
<version>${imageio.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.tess4j</groupId>
|
||||
<artifactId>tess4j</artifactId>
|
||||
<version>${tess4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bytedeco</groupId>
|
||||
<artifactId>tesseract-platform</artifactId>
|
||||
<version>${tesseract-platform.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<properties>
|
||||
<core-image.version>1.3.5</core-image.version>
|
||||
<ij.version>1.51h</ij.version>
|
||||
<imageio.version>3.3.2</imageio.version>
|
||||
<tess4j.version>4.5.1</tess4j.version>
|
||||
<tesseract-platform.version>4.1.0-1.5.2</tesseract-platform.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,28 @@
|
|||
package com.baeldung.tesseract;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.io.File;
|
||||
|
||||
import net.sourceforge.tess4j.Tesseract;
|
||||
import net.sourceforge.tess4j.TesseractException;
|
||||
|
||||
public class Tess4JExample {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String result = null;
|
||||
try {
|
||||
File image = new File("src/main/resources/images/baeldung.png");
|
||||
Tesseract tesseract = new Tesseract();
|
||||
tesseract.setLanguage("spa");
|
||||
tesseract.setPageSegMode(1);
|
||||
tesseract.setOcrEngineMode(1);
|
||||
tesseract.setHocr(true);
|
||||
tesseract.setDatapath("src/main/resources/tessdata");
|
||||
result = tesseract.doOCR(image, new Rectangle(1200, 200));
|
||||
} catch (TesseractException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.baeldung.tesseract;
|
||||
|
||||
import org.bytedeco.javacpp.BytePointer;
|
||||
import org.bytedeco.leptonica.PIX;
|
||||
import org.bytedeco.tesseract.TessBaseAPI;
|
||||
|
||||
public class TesseractPlatformExample {
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
TessBaseAPI tessApi = new TessBaseAPI();
|
||||
tessApi.Init("src/main/resources/tessdata", "eng", 3);
|
||||
tessApi.SetPageSegMode(1);
|
||||
PIX image = org.bytedeco.leptonica.global.lept.pixRead("src/main/resources/images/baeldung.png");
|
||||
tessApi.SetImage(image);
|
||||
|
||||
BytePointer outText = tessApi.GetUTF8Text();
|
||||
System.out.println(outText.getString());
|
||||
tessApi.End();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 648 KiB |
Binary file not shown.
After Width: | Height: | Size: 217 KiB |
|
@ -0,0 +1,9 @@
|
|||
Der ,.schnelle” braune Fuchs springt
|
||||
iiber den faulen Hund. Le renard brun
|
||||
«rapide» saute par-dessus le chien
|
||||
paresseux. La volpe marrone rapida
|
||||
salta sopra il cane pigro. El zorro
|
||||
marron rapido salta sobre el perro
|
||||
perezoso. A raposa marrom rapida
|
||||
salta sobre 0 cao preguicoso.
|
||||
|
Loading…
Reference in New Issue