Created
February 13, 2024 15:41
-
-
Save incubated-geek-cc/415a18a23fcde33ee9d4196197f09e3f to your computer and use it in GitHub Desktop.
Boilerplate for Tess4J v4. Code snippet demo for step 1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import net.sourceforge.tess4j.Tesseract; | |
public class Test { | |
public static void main(String[] args) { | |
Tesseract instance = new Tesseract(); | |
int imageDPI = 300; | |
Path currentRelativePath = Paths.get(""); | |
String s = currentRelativePath.toAbsolutePath().toString(); | |
File dataDir = new File(s, "tessdata"); | |
if(dataDir.exists()) { | |
instance.setDatapath(dataDir.getAbsolutePath()); | |
/* START TO DO LOGIC HERE*/ | |
instance.setLanguage("eng+osd+equ"); | |
/* | |
OCR engine modes (oem) | |
0. Legacy engine only | |
1. Neural nets LSTM engine only | |
2. Legacy + LSTM engines | |
3. Default, based on what is available | |
*/ | |
instance.setOcrEngineMode(1); | |
instance.setTessVariable("user_defined_dpi", imageDPI+""); | |
/* //END TO DO LOGIC HERE*/ | |
// String text = instance.doOCR(new File("bday_card.jpg")); | |
// System.out.print(text); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment