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

"Warning. Invalid resolution 0 dpi. Using 70 instead." with 321-Tesseract-4 branch #397

Closed
masterisk opened this issue Mar 7, 2018 · 13 comments

Comments

@masterisk
Copy link

I am using the 321-Tesseract-4 branch for LSTM support, I am capturing a section of the screen and creating a Bitmap object to pass to the TesseractEngine but am only getting the "Warning. Invalid resolution 0 dpi. Using 70 instead." error.

I tried setting Bitmap object resolutionwit "Bitmap.setResolution(96, 96);"
as well as trying "engine.SetVariable("image_default_resolution", input.VerticalResolution);"

When I used the Tesseract 3 nuget package I did not encounter this error in the same project. Is this an issue from the newer version of leptonica? or something I can work around programmatically?

@tdhintz
Copy link
Contributor

tdhintz commented Mar 7, 2018 via email

@masterisk
Copy link
Author

I see that now. So is this branch not usable then? I can't seem to get any kind of accurate OCR results using it while I get the dpi errors.

@tdhintz
Copy link
Contributor

tdhintz commented Mar 7, 2018 via email

@masterisk
Copy link
Author

When I use the Tesseract Nuget package that is hosted in the Nuget database, the OCR works for the most part. But I wanted to try out Tesseract 4 LSTM for increased accuracy.

So is this due to a change in just the Leptonica API, I wonder?

I will dig around and see what I can do with modifying Pix.Create(). I'm not hopeful though, very novice over here.

Thanks for your suggestions!

@tdhintz
Copy link
Contributor

tdhintz commented Mar 7, 2018 via email

@masterisk
Copy link
Author

masterisk commented Mar 7, 2018

I've tried the traineddata files from both:
https://github.com/tesseract-ocr/tessdata
https://github.com/tesseract-ocr/tessdata_fast

I've also tried using EngineMode.Default and EngineMode.LstmOnly
I'm using these on very legible, small data set to test with, and its not getting ANY of it correct. Is there another set of traineddata you would recommend?

I'm wondering if the lack of dpi setting is causing the image to bee too scrunched or stretched to be legible.

@masterisk
Copy link
Author

masterisk commented Mar 7, 2018

I've implemented the overloaded Pix.Create() to pass the resolution and then and used
LeptonicaAPI.cs wrapper’s pixSetResolution() to set that before OCRing... I no longer get the dpi error! But still not getting legible OCR data. I wonder if I'm setting the DPI to the correct value by using:

public Pix Convert(Bitmap img)
{
var pixDepth = GetPixDepth(img.PixelFormat);
var dpiX = (int)img.HorizontalResolution;
var dpiY = (int)img.VerticalResolution;
var pix = Pix.Create(img.Width, img.Height, pixDepth, dpiX, dpiY);
...
}

Or if there really is an issue with training data.

@tdhintz
Copy link
Contributor

tdhintz commented Mar 7, 2018 via email

@masterisk
Copy link
Author

I had to use a snippet from the Pix constructor to turn handle (and Handle object) into a HandleRef object. But I have that part working now, no more DPI warning. But I still don't have a useable OCR reading. I'm going to try re-downloading the eng.trandata.

@masterisk
Copy link
Author

I found out that my problem was that the options for PageSegMode are different in the 4.0 wrapper.

Everything works as intended now!

@wilfredcho
Copy link

@masterisk Can you elaborate the problem you faced with the PageSegMode please and which option you used?

@masterisk
Copy link
Author

masterisk commented Jun 13, 2018

@wilfredcho after changing to using Tesseract 4, I had kept the same PageSegMode setting that I had used for previous version:

var page = engine.Process(input, PageSegMode.LSTM)

or something of that nature. But in Tesseract 4, the options have changed to the following:

namespace Tesseract
{
    public enum PageSegMode
    {
        OsdOnly = 0,
        AutoOsd = 1,
        AutoOnly = 2,
        Auto = 3,
        SingleColumn = 4,
        SingleBlockVertText = 5,
        SingleBlock = 6,
        SingleLine = 7,
        SingleWord = 8,
        CircleWord = 9,
        SingleChar = 10,
        SparseText = 11,
        SparseTextOsd = 12,
        RawLine = 13,
        Count = 14
    }
}

@ghost
Copy link

ghost commented Jul 11, 2018

Is there a way to detect PNM images resolution?

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

No branches or pull requests

3 participants