tess4j: Read text in rectangle of image

258 views
Skip to first unread message

Dattatraya Tembare

unread,
Jun 8, 2018, 3:07:37 PM6/8/18
to tesseract-ocr
I wrote this piece of code:
public static void main(String[] args) {
 
String fileStr = "C:/EA/mp-out/im/1/3/1-0.png";
 
File file = new File(fileStr);
 
//380x45+220+170
 
int xsize = 220;
 
int ysize = 170;
 
BufferedImage bufImage;
 
ByteBuffer buf = null;
 
try {
 bufImage
= ImageIO.read(file);
 
IIOImage image=new IIOImage(bufImage,null,null);
 buf
= ImageIOHelper.getImageByteBuffer(image);
 
} catch (IOException e2) {
 e2
.printStackTrace();
 
}
 
Rectangle rect = new Rectangle(0, 0, 380, 45); // define an equal or smaller region of interest on the image
 
int bpp = 8; //Gray=8, RGB=24
 
 
Tesseract in = new ReadImageText().getTesseractInstance("C:/Program Files (x86)/Tesseract-OCR/tessdata/", "eng");
 
try {
 
String resultText = in.doOCR(xsize, ysize, buf, "C:/Program Files (x86)/Tesseract-OCR/tessdata/hin.traineddata", rect, bpp);
 log
.info("resultText: {}", resultText);
 
} catch (TesseractException e) {
 e
.printStackTrace();
 
}
 
}
Result: Not sure what am I missing?
14:54:56.534 [main] ERROR net.sourceforge.tess4j.Tesseract - null
java.lang.NullPointerException: null
	at net.sourceforge.tess4j.Tesseract.getOCRText(Tesseract.java:434)
	at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:351)
	at com.ea.ocr.tesseract.ReadImageText.main(ReadImageText.java:74)
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages