Reputation: 111
Tesseract provides confidence score in TSV config, but i am looking for confidence score of whole image processed.
Upvotes: 4
Views: 565
Reputation: 5486
Below code will return confidence score per image.
String datapath = "D:\\Tesseract";
String language = "eng";
TessAPI1 api = new TessAPI1();
TessBaseAPI handle = api.TessBaseAPICreate();
File image = new File("testocr.png");
Leptonica leptInstance = Leptonica.INSTANCE;
Pix pix = leptInstance.pixRead(image.getPath());
api.TessBaseAPIInit3(handle, datapath, language);
api.TessBaseAPISetImage2(handle, pix);
int conf = api.TessBaseAPIMeanTextConf(handle);
System.out.println("conf" + conf);
// release Pix and Boxa resources
LeptUtils.dispose(pix);
Below maven dependency you need to add:
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>4.3.0</version>
</dependency>
Upvotes: 1