different results between launch from command line or c++ program with tesseract/baseapi

704 views
Skip to first unread message

vallet alexis

unread,
Feb 18, 2014, 9:21:17 AM2/18/14
to tesser...@googlegroups.com
Hello everyone !

I am trying to use tesseract inside a c++ software. 
I succeed in launching tesseract from the shell using command line "tesseract img.tif text -l fra -psm 1 hocr", what gives me good results, but when it comes to running the exact same process from tesseract baseapi (to make the software more portable) i have slightly poorer results : on an image, i go from 160 to 137 detected words, and the detected words are not as good as they used to be (ie they are not always correct and contain  unwanted symbols).
So my goal is to have at least the same results, but I cannot understand why they are different

So my question is how to translate "tesseract img.tif text -l fra -psm 1 hocr" to code ?
So far i am using the code below, which uses openCV to read the image :

	Mat img=imread(img.tif,CV_LOAD_IMAGE_GRAYSCALE);  //load the grayscale image
	tesseract::TessBaseAPI tess;
	tess.Init(NULL, "fra", tesseract::OEM_DEFAULT);   //matches -l fra fromcommand line,  i guess OEM_default was the one used by the command line ?
	tess.SetPageSegMode(tesseract::PSM_AUTO);   //matches -psm 1 from the command line
	tess.SetImage((uchar*)img.data, img.cols, img.rows, 1, img.cols); //define the image
	string text=tess.GetHOCRText(0); //get the result into text


So I thought I had translated the various options, but given the slightly different results i guess i am not doing it properly. 
Can it come from the fact in the program i am giving a grayscale image, while in command line it is a color image ? If yes, how can i set a color image for the text recognition ?
If there is some way to get read of the openCV library ang directly give the path of the image so that tesseract can use its own tools I would also be glad to use it !

I am using tubuntu 13.10 and tesseract 3.02.01

thanks in advance for any help on how to modify the code !

Alexis

Nick White

unread,
Feb 18, 2014, 10:11:51 AM2/18/14
to tesser...@googlegroups.com
Hi Alexis,

Firstly, to help you, the main tesseract command line program just
uses the main API itself, it doesn't do anything special. It's the
api/tesseractmain.cpp file in the Tesseract source code. So give
that a read if you want to trace exactly what Tesseract is doing.

I think you're probably right, it's likely related to the image
loading. The main Tesseract command line uses Leptonica (see the
pixRead lines in api/tesseractmain.cpp), so maybe you'd have better
luck with that. Sorry I can't be more authoritative, but I haven't
used the API much for a little while.

Nick
> --
> --
> You received this message because you are subscribed to the Google
> Groups "tesseract-ocr" group.
> To post to this group, send email to tesser...@googlegroups.com
> To unsubscribe from this group, send email to
> tesseract-oc...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/tesseract-ocr?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "tesseract-ocr" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to tesseract-oc...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Quan Nguyen

unread,
Feb 18, 2014, 6:08:20 PM2/18/14
to tesser...@googlegroups.com
You are ocring two different images, hence the difference in result. PSM_AUTO corresponds to 3, not 1. Peforming OCR on the same image and same PSM should produce the same result.

Aleksander Grzyb

unread,
Feb 20, 2014, 11:00:00 AM2/20/14
to tesser...@googlegroups.com
I am using Tesseract inside iOS application and I had the same problem that results from OCR in app were different from command line. For me the problem was in Tesseract API, in baseapi.h quoting "... Set the current page segmentation mode. Defaults to PSM_SINGLE_BLOCK. ...", which is number 5 of pagesegmode but in command line tool is quoting "3 = Fully automatic page segmentation, but no OSD. (Default)". So this defaults parameters are different, for me was the solution to set the parameter in my app to parameter from command line and the results were the same. Best regards!
Reply all
Reply to author
Forward
0 new messages