Java image recognition technology uses tess4j technology.
- Download Tess4J-3.2.1-src.zip
- Download tesseract-ocr-setup-3.02.02.exe
The project uses Ant to build, first add a sentence <javac srcdir="src" destdir="bin" /> in build.xml, otherwise it may not be able to build project. Build the project "File→New→Other" and select Java Project from Existing Ant Buildfile.
Browse the build.xml file and build the project.
The completed directory is as follows:
Import the support jar in the lib folder into the project, and copy win32-x86 and win32-x86-64 to the bin directory.
Install tesseract-ocr-setup-3.02.02.exe, the installation is completed as follows:
After completing the above steps, you can write sample code.
public class TestDemo { @Test public void test() throws Exception { File imageFile = new File("Y:/ocr/test/d.png"); if (imageFile.exists()){ Tesseract1 tess = new Tesseract1 (); tess.setDatapath("C:/Program Files (x86)/Tesseract-OCR");//Set the Tesseract-OCR path tess.setLanguage("eng"); List<String> configs = new ArrayList<>(); configs.add("digits");//Set in the Tesseract-OCR\tessdata\configs directory tess.setConfigs(configs);//Add settings String s = tess.doOCR(imageFile); System.out.println("decode is "+s); } } }
Recognize 123 in the picture: The
recognition result is as follows: The
attachment cannot be uploaded. If you want the file, add the group QQ227297422.