Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSD Not working --psm=0,1,12 #1463

Closed
abir26 opened this issue Apr 10, 2018 · 7 comments
Closed

OSD Not working --psm=0,1,12 #1463

abir26 opened this issue Apr 10, 2018 · 7 comments
Labels
OSD Orientation and Script Detection

Comments

@abir26
Copy link

abir26 commented Apr 10, 2018

Environment

  • Tesseract Version: Tesseract v4.0.0-beta.1-77
  • Commit Number: g8182
  • Platform: ubuntu 16.04
  • Leptonica Version: Leptonica-1.75.3

Current Behavior:

I get this error "Error: Illegal Parameter specification!
"Fatal error encountered!" == NULL:Error:Assert failed:in file globaloc.cpp, line 75" or an empty output whenever I use the OSD (--psm=0,1,12). Also when I tried to extract Orientation, Direction and Skew angle I get 0 for all of them no matter what picture I use.

This is the picture I used:
eurotext_skew tif
In command line I get this:
res cmd

I tested it with the c++ code "Orientation and script detection (OSD) example" provided in the wiki:
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); api->Init(dataPath, "eng"); api->SetPageSegMode(tesseract::PSM_AUTO_OSD); api->SetVariable("tessedit_ocr_engine_mode","0"); api->SetVariable("tessedit_enable_dict_correction","1"); Pix *image = pixRead(imagePath); api->SetImage(image); tesseract::Orientation orientation; tesseract::WritingDirection direction; tesseract::TextlineOrder order; float deskew_angle; api->Recognize(0); tesseract::PageIterator* it = api->AnalyseLayout(); it->Orientation(&orientation, &direction, &order, &deskew_angle); printf("Orientation: %d;\nWritingDirection: %d\nTextlineOrder: %d\n Deskew angle: %.4f\n", orientation, direction, order, deskew_angle); // Get OCR result outText = api->GetUTF8Text(); meanConf=api->MeanTextConf();
I get this result :
test osd

And I tried it with a java code with the skewed image and Euronext.tif, I got this error:
osd problem

@amitdo
Copy link
Collaborator

amitdo commented Apr 10, 2018

--psm 0 not --psm=0
Same for oem.

Also see:
#1167 (comment)

@Shreeshrii
Copy link
Collaborator

$tesseract -v
tesseract 4.0.0-beta.1-64-gd284
 leptonica-1.76.0
  libjpeg 8d (libjpeg-turbo 1.3.0) : libpng 1.2.50 : libtiff 4.0.3 : zlib 1.2.8 : libopenjp2 2.3.0
 Found AVX
 Found SSE
  1. Use -l osd (not eng)

  2. For command line, the following works (modify paths for your setup)

$tesseract devatest-rotated-270.png stdout  --tessdata-dir /mnt/c/Users/User/shree/tessdata_fast --psm 0 --oem 0 -l osd

Page number: 0
Orientation in degrees: 270
Rotate: 90
Orientation confidence: 7.07
Script: Devanagari
Script confidence: inf
  1. For api example, see the following
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
int main()
{
    const char* inputfile = "/mnt/c/Users/User/shree/tesseract-HEAD/testing/devatest-rotated-270.png";
    PIX *image = pixRead(inputfile);
    tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
    api->Init(NULL, "osd");
// Get OSD - old example code
    tesseract::Orientation orientation;
    tesseract::WritingDirection direction;
    tesseract::TextlineOrder order;
    float deskew_angle;
    api->SetPageSegMode(tesseract::PSM_AUTO_OSD);
    api->SetImage(image);
    api->Recognize(0);
    tesseract::PageIterator* it =  api->AnalyseLayout();
    it->Orientation(&orientation, &direction, &order, &deskew_angle);
    printf("Orientation: %d;\nWritingDirection: %d\nTextlineOrder: %d\n" \
    "Deskew angle: %.4f\n",
    orientation, direction, order, deskew_angle);
//Get OSD - new code
    int orient_deg;
    float orient_conf;
    const char* script_name;
    float script_conf;
    api->DetectOrientationScript(&orient_deg, &orient_conf, &script_name, &script_conf);
    printf("************\n Orientation in degrees: %d\n Orientation confidence: %.2f\n"
    " Script: %s\n Script confidence: %.2f\n",
    orient_deg, orient_conf,
    script_name, script_conf);
    // Destroy used object and release memory
    api->End();
    pixDestroy(&image);
    return 0;
}

Console output

Detected 127 diacritics
Orientation: 3;
WritingDirection: 0
TextlineOrder: 2
Deskew angle: -0.0071
************
 Orientation in degrees: 270
 Orientation confidence: 7.07
 Script: Devanagari
 Script confidence: inf

@Shreeshrii
Copy link
Collaborator

Re: "Error: Illegal Parameter specification!

See #1010

we have no problem for the tesseract executable or the training programs which are provided by Tesseract. Nor will external software have a problem as long as it does not set LC_NUMERIC.
Maybe Java uses the environment settings to set LC_NUMERIC internally. That would explain the reported problem.

So, far java, python etc

Locale should rather be set explicitly. The workaround is to set LC_NUMERIC=en_US.UTF-8.

@abir26
Copy link
Author

abir26 commented Apr 10, 2018

ok now it works when I used --psm 1 --oem 0 for the images :phototest-rotated-R/L/180.png . However it doesn't work with the image above. same for the C++ code.

@amitdo
Copy link
Collaborator

amitdo commented Apr 11, 2018

Paste the full command.

it doesn't work with the image above

What do you mean by 'it doesn't work'? What's the output?

@abir26
Copy link
Author

abir26 commented Apr 11, 2018

I thought Tesseract does the image processing operations internally so it will determine the skew angle, straighten and do the OCR on the processed image. But here I get the orientation in degrees and the Deskew angle equal to 0 for the image Euronext_skew.tif and obviously couldn't recognize the image content.
psm0oem0
psm1oem0
api example code:
cpp

Anyway, I will just need to improve the quality of the OCR input externally in my project.
Thank you for your help.

@abir26 abir26 closed this as completed Apr 11, 2018
@amitdo
Copy link
Collaborator

amitdo commented Apr 11, 2018

tesseract --tessdata-dir ~/tesseract/tessdata/fast ~/Downloads/skwedlat.png - -l Latin --psm 6

The (quick) [brown] {fox} jumps!
Over the $43,456.78 <lazy? #90 dog
& duck/goos¢. as 12.5% of g-mail
from aspammer@website- cu is spam.
Der schnelle” braune Fuchs springt
über den faulen Hund. Le renard brun
«rapide» saute par-dessus ie chien
paresseux. La volpe marrone rapida
csalta sopta i] cane pigro. E1 zorro
marrón rápido salta sobte el perro
perezoso. A raposa marrom rápida
salta sobte o cão preguiçoso.

tesseract --tessdata-dir ~/tesseract/tessdata/best ~/Downloads/skwedlat.png - -l Latin --psm 6

The (quick) [brown] £fox}3 jumps!
Over the $43,456.78 <1azy7 490 dog
& duck/g00S¢> as 12.5% of E-mail
from aspammer@website-Cat is spam.
Der schnelle” braune Fuchs springt
über den faulen Hund. Le renard bruB
«rapide» saute par-dessus le chien
paresseu*X-. La volpe marrone rapida
salta sopra jì cane pigro- E1 zorro
marrón rápido salta sobre el perro
perezos0. A raposa marrom rápida
salta sobre o cão preguiç0s0-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OSD Orientation and Script Detection
Projects
None yet
Development

No branches or pull requests

3 participants