pyton alternative java, jar and java code in eclipse

 





import net.sourceforge.tess4j.ITesseract;

import net.sourceforge.tess4j.Tesseract;

import net.sourceforge.tess4j.TesseractException;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;


public class ImageToTextOCR {

    public static void main(String[] args) {

        File imageFile = new File("C:/path/to/123.jpg");

        File outputFile = new File("C:/path/to/image_to_text.txt");


        ITesseract instance = new Tesseract();

        instance.setDatapath("C:/tessdata"); // Folder with traineddata files

        instance.setLanguage("tel+eng");


        try {

            String result = instance.doOCR(imageFile);

            try (FileWriter writer = new FileWriter(outputFile)) {

                writer.write(result);

            }

            System.out.println("Text extracted and saved to: " + outputFile);

        } catch (TesseractException | IOException e) {

            System.err.println("Error: " + e.getMessage());

        }

    }

}

Popular posts from this blog

SAP CPI : camle expression in sap cpi , cm, router, filter and groovy script. format

SAP CPI camel conditions and xpath conditions

oauth call to cpi integraiton suite from sap apim