package shop.alien.util.ocr;

import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;

/**
 * @author ssk
 * @version 1.0
 * @date 2024/10/10 13:37
 */
public class OCRUtil {
    public static void main(String[] args) {
        // 创建Tesseract实例
        Tesseract tesseract = new Tesseract();

        try {
            // 设置Tesseract的语言库路径
            tesseract.setDatapath("D:\\SoftWareProgram\\Tesseract-OCR\\tessdata");

            // 设置识别语言，默认为英文，中文简体设置为"chi_sim"
            tesseract.setLanguage("chi_sim");

            // 识别图片文件
            String result = tesseract.doOCR(new File("C:\\Users\\17238\\Pictures\\4A375133A7F453966AF794D0356B80AA.jpg"));
            System.out.println(result);
        } catch (TesseractException e) {
            e.printStackTrace();
        }
    }

}
