Answer the question
In order to leave comments, you need to log in
How to detect text from image using javacpp tesseract?
BytePointer outText;
TessBaseAPI api = new TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api.Init("C:/Users/Dom/GlobalWeather/", "eng") != 0) {
System.err.println("Could not initialize tesseract.");
System.exit(1);
}
File imgPath = new File("test.png");
ByteArrayOutputStream baos=new ByteArrayOutputStream();
BufferedImage img;
try {
img = ImageIO.read(imgPath);
ImageIO.write(img, "png", baos );
} catch (IOException e) {
System.err.println("Reading file or writing byte[] failed.");
e.printStackTrace();
}
byte[] imageInByte=baos.toByteArray();
PIX image = pixReadMemPng(imageInByte, imageInByte.length);
api.SetImage(image);
// Get OCR result
outText = api.GetUTF8Text();
System.out.println("OCR output:\n" + outText.getString());
// Destroy used object and release memory
api.End();
outText.deallocate();
pixDestroy(image);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question