Running OSD support of Tesseract OCR

10,029 views
Skip to first unread message

Chirag Jain

unread,
Mar 1, 2012, 4:26:54 AM3/1/12
to tesseract-ocr
Dear Sir,

I download tesseract-ocr-3.01-win32-portable.zip from the following
link
http://code.google.com/p/tesseract-ocr/downloads/list

I am finding it difficult to use OSD feature of Tesseract OCR.

I used the following command:

tesseract.exe phototest.tif test_osd -psm 0

It generated test_osd.txt as an output but it was an empty file.

Kindly let me know if I am missing some step.

Thanks and Regards,
Chirag Jain

Sriranga(78yrs)

unread,
Mar 1, 2012, 7:46:40 AM3/1/12
to tesser...@googlegroups.com
When tested I got "error during the process" displayed in the cmd.


--
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

Sriranga(78yrs)

unread,
Mar 1, 2012, 7:47:42 AM3/1/12
to tesser...@googlegroups.com
also got empty text.

koray

unread,
Mar 3, 2012, 8:42:01 AM3/3/12
to tesseract-ocr
OSD returns emty text when I tried. Can anyone please clarify if
this is a bug or I m doing things wrong?

Chirag

unread,
Mar 14, 2012, 5:52:20 AM3/14/12
to tesser...@googlegroups.com
Hi all,

I was able to successfully test orientation detection (after stepping though the code) for various scripts using following commands:

English: tesseract.exe  english_doc.tif  test_osd -l eng -psm 0 
Japanese: tesseract.exe  japanese_doc.tif  test_osd -l jpn -psm 0
Korean: tesseract.exe  korean_doc.tif  test_osd -l kor -psm 0

In these cases, the executable search for eng.traineddata, jpn.traineddata and kor.traineddata respectively along with osd.traineddata.

The performance is really good.


However, it seems like Tesseract is detecting orientation given script.


If I run the executable as following: 

Japanese: tesseract.exe  japanese_doc.tif  test_osd  -psm 0
Korean: tesseract.exe  korean_doc.tif  test_osd  -psm 0

The results are not good. It seems like script detection is not robust.

Am I missing some step? Kindly clarify. 


Regards,
Chirag


On Sat, Mar 3, 2012 at 7:12 PM, koray <uca...@ug.bilkent.edu.tr> wrote:
 OSD returns emty text when I tried. Can anyone please clarify if
this is a bug or I m doing things wrong?

Sriranga(78yrsold)

unread,
Mar 14, 2012, 6:21:05 AM3/14/12
to tesser...@googlegroups.com
 I noticed "-l lang" before "-psm 0" is missing in your commandline. In the absence of "-l lang" tesseract will always  assume as "-l eng".

extract of help is reproduced below:

M:\>tesseract.exe -h
Usage:tesseract.exe imagename outputbase [-l lang] [-psm pagesegmode] [configfil
e...]
pagesegmode values are:
0 = Orientation and script detection (OSD) only.
1 = Automatic page segmentation with OSD.
2 = Automatic page segmentation, but no OSD, or OCR
3 = Fully automatic page segmentation, but no OSD. (Default)
4 = Assume a single column of text of variable sizes.
5 = Assume a single uniform block of vertically aligned text.
6 = Assume a single uniform block of text.
7 = Treat the image as a single text line.
8 = Treat the image as a single word.
9 = Treat the image as a single word in a circle.
10 = Treat the image as a single character.
-l lang and/or -psm pagesegmode must occur before anyconfigfile.

Sriranga(78yrsold)

unread,
Mar 14, 2012, 6:35:03 AM3/14/12
to tesser...@googlegroups.com
one more important - please test again as follows:
1st test:tesseract.exe  japanese_doc.tif  test_osd -l jpn -psm 3
2nd test:tesseract.exe  japanese_doc.tif  test_osd         -psm 3
Please check the output text files "test_osd"  - you will find difference in script between two.

Chirag

unread,
Mar 14, 2012, 6:27:16 AM3/14/12
to tesser...@googlegroups.com
Thanks Sriranga for the response.

If I am specifying the script, it is just orientation detection of that particular script.

The script detection is still a question mark. 

Regards,
Chirag


On Wed, Mar 14, 2012 at 3:51 PM, Sriranga(78yrsold) <withbl...@gmail.com> wrote:

Chirag

unread,
Mar 14, 2012, 6:20:29 AM3/14/12
to tesser...@googlegroups.com
Just to add one point:

By chance is it assuming it to be English if I don't mention -l <lang>?

In any case, what option/argument should be given for detecting script?

Regards,
Chirag


On Wed, Mar 14, 2012 at 3:22 PM, Chirag <chir...@gmail.com> wrote:

Chirag

unread,
Mar 14, 2012, 7:17:29 AM3/14/12
to tesser...@googlegroups.com
With -psm 3, I got non-empty files (test_osd.txt)  which were empty with -psm 0. This is true for both with/without -l options.

However, the results of detectOS is same for both -psm [0/3] option for any of with/without -l options.

Please note that I have modified the code slightly to call detectOS separately, which has been doing a good job for orientation detection given script.  I am struggling to detect the script of the input document. 

Regards,
Chirag

Sriranga(78yrsold)

unread,
Mar 14, 2012, 9:27:11 AM3/14/12
to tesser...@googlegroups.com
I tested using my own lang.tif as follows:
 1) using with -l option -psm 3 ->pl see attached testtif-osd.txt. (non-english)
  2)using without -l option -psm3 ->pl see attached 2testtif-osd.txt. (in English)
In both cases there are no empty output but in different lang

Extract of cmd reproduced below, if used -psm 0
M:\>tesseract.exe test.tif 2testtif-osd    -psm 0  
Tesseract Open Source OCR Engine v3.02 with Leptonica
Error during processing.

M:\>tesseract.exe test.tif 2testtif-osd -l k27   -psm 0
Tesseract Open Source OCR Engine v3.02 with Leptonica
Error during processing.
testtif-osd.txt
2testtif-osd.txt

Chirag

unread,
Mar 15, 2012, 3:34:21 AM3/15/12
to tesser...@googlegroups.com
Thanks Sriranga for the response.

I was able to perform automatic orientation detection along with page segmentation but I had to supply the script information in the argument for Non English scripts.

I still could not perform automatic script detection. 

Regards
Chirag


2012/3/14 Sriranga(78yrsold) <withbl...@gmail.com>

Sriranga(78yrsold)

unread,
Mar 15, 2012, 4:41:06 AM3/15/12
to tesser...@googlegroups.com
it would be better to furnish version of tesseract-ocr used and also type of OS used by you.
also upload your used image file for recreating your problem.

zdenko podobny

unread,
Nov 18, 2012, 3:27:20 PM11/18/12
to tesser...@googlegroups.com
Hi all,

you will not get OSD (Orientation and script detection) output information with tesseract executable. At the moment tesseract provide (save) only ocr result. Somebody could consider help (tesseract --help) misleading because it enumerate all possible page segmentation modes. I think that starting with other than 0 psm would also trigger question...

OSD info you get via API. Here is simple snippet:

    inputfile = "/usr/src/tesseract-3.02/eurotextUpsideDown.png";
    image = pixRead(inputfile);

    api->Init("/usr/src/tesseract-3.02/", "eng");
    api->SetPageSegMode(tesseract::PSM_AUTO_OSD);
    api->SetImage(image);
    api->Recognize(0);

    tesseract::PageIterator* it =  api->AnalyseLayout();
    tesseract::Orientation orientation;
    tesseract::WritingDirection direction;
    tesseract::TextlineOrder order;
    float deskew_angle;

    it->Orientation(&orientation, &direction, &order, &deskew_angle);
    printf("Orientation: %d;\nWritingDirection: %d\nTextlineOrder: %d\n" \
           "Deskew angle: %.4f\n",
           orientation, direction, order, deskew_angle);

In output you can see these information(eurotextUpsideDown.png is 180 degree rotated image eurotext.tif):

Orientation: 2;

WritingDirection: 0

TextlineOrder: 2

Deskew angle: -0.0038


This means that page is upside down (Orientation)[1], text is written from left to right (WritingDirection)[2], lines are ordered from top to down (TextlineOrder)[3], and there is small deskew angle[4].

As you can see attributes WritingDirection, TextlineOrder, Deskew do not reflect that page is upside down, so you will get the same result for eurotext.tif.

--
Zdenko

On Tue, Nov 13, 2012 at 10:26 AM, Alex <miller.j...@gmail.com> wrote:
Hello,Chirag.

I am also trying to find a way to detect the script of the input document.

Kindly let me know if  you have some progress.

Thanks and Regards,
Alex



在 2012年3月14日星期三UTC+8下午7时17分29秒,Chirag Jain写道:

Mikael Egibyan

unread,
Mar 8, 2016, 2:23:30 AM3/8/16
to tesseract-ocr
I am using /MT lib binaries and your code crashes on

it->Orientation(&orientation, &direction, &order, &deskew_angle);

Any idea what is wrong?

Thanks,
Mikayel

YounesC

unread,
Apr 1, 2016, 2:36:05 AM4/1/16
to tesseract-ocr
hi
I use tesseract 3.02
when I use mode PSM_AUTO_OSD,
the orientation finder works just fine:
      tesseract::PageIterator* it = api->AnalyseLayout();
    tesseract::Orientation orientation;
    tesseract::WritingDirection direction;
    tesseract::TextlineOrder order;
    float deskew_angle;

    it->Orientation(&orientation, &direction, &order, &deskew_angle);
    printf("Orientation: %d;\nWritingDirection: %d\nTextlineOrder: %d\n" \
           "Deskew angle: %.4f\n",
           orientation, direction, order, deskew_angle);

When I use PSM_OSD_ONLY, the orientation finder doesn't work.
any ideas?
do I have to upgrade to Tesseract 3.04?
Reply all
Reply to author
Forward
0 new messages