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

OCR Tesseract: "Warning: Invalid resolution 0 dpi. Using 70 instead." #881

Closed
Blightbuster opened this issue Mar 9, 2020 · 4 comments · May be fixed by #1543
Closed

OCR Tesseract: "Warning: Invalid resolution 0 dpi. Using 70 instead." #881

Blightbuster opened this issue Mar 9, 2020 · 4 comments · May be fixed by #1543

Comments

@Blightbuster
Copy link

Blightbuster commented Mar 9, 2020

Summary of your issue

When performing ocr on a captured screenshot, I get the warning "Warning: Invalid resolution 0 dpi. Using 70 instead.". I capture the screenshot as System.Drawing.Bitmap which does contain the correct dpi. When converting the bitmap to OpenCvSharp.Mat and then performing ocr on the mat it prints the warning into the console.

Environment

Im using OpenCVSharp4 4.2.0.20200208
and OpenCVSharp4.runtime.win 4.2.0.20200208

Example code:

private Bitmap GetScreenshot(int x, int y)
{
    var bmp = new Bitmap(200, 50, PixelFormat.Format24bppRgb);

    var gfx = Graphics.FromImage(bmp);
    var size = new System.Drawing.Size(200, 50);

    gfx.CopyFromScreen(0, 0, 0 , 0, size);
    return bmp;
}

private string OCR(Bitmap bmp)
{
    var text = "";

    using (var mat = BitmapConverter.ToMat(bmp))
    {
        _ocrTesseract.Run(mat, out text, out _, out _, out _);
    }

    return text;
}

Output:

Warning: Invalid resolution 0 dpi. Using 70 instead.

What did you intend to be?

Id like to either some how tell tesseract the dpi of the bitmap or mute the warning since 70 dpi is close enought to the actual dpi.

@shimat shimat added the problem label Apr 18, 2020
@shimat
Copy link
Owner

shimat commented Apr 18, 2020

I couldn't find a way to do it either. 😢

It might be possible to do that by rewriting the OpenCV implementation.
https://github.com/opencv/opencv_contrib/blob/master/modules/text/src/ocr_tesseract.cpp#L206

tess.SetImage((uchar*)image.data, image.size().width, image.size().height, image.channels(), image.step1());

Pix* pix = tess.GetInputImage();
pixSetXRes(*pix, 70);
pixSetYRes(*pix, 70);

tess.Recognize(0);
...

@stale
Copy link

stale bot commented Oct 15, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Oct 15, 2020
@stale stale bot closed this as completed Oct 22, 2020
@stone89son
Copy link

Summary of your issue

When performing ocr on a captured screenshot, I get the warning "Warning: Invalid resolution 0 dpi. Using 70 instead.". I capture the screenshot as System.Drawing.Bitmap which does contain the correct dpi. When converting the bitmap to OpenCvSharp.Mat and then performing ocr on the mat it prints the warning into the console.

Environment

Im using OpenCVSharp4 4.2.0.20200208
and OpenCVSharp4.runtime.win 4.2.0.20200208

Example code:

private Bitmap GetScreenshot(int x, int y)
{
    var bmp = new Bitmap(200, 50, PixelFormat.Format24bppRgb);

    var gfx = Graphics.FromImage(bmp);
    var size = new System.Drawing.Size(200, 50);

    gfx.CopyFromScreen(0, 0, 0 , 0, size);
    return bmp;
}

private string OCR(Bitmap bmp)
{
    var text = "";

    using (var mat = BitmapConverter.ToMat(bmp))
    {
        _ocrTesseract.Run(mat, out text, out _, out _, out _);
    }

    return text;
}

Output:

Warning: Invalid resolution 0 dpi. Using 70 instead.

What did you intend to be?

Id like to either some how tell tesseract the dpi of the bitmap or mute the warning since 70 dpi is close enought to the actual dpi.
this problem not opencvsharp, tesseract of problem, set dpi to 300 to fix.
ref link:
https://www.google.com/search?q=tesseract+dpi+parameter&rlz=1C1FQRR_enJP969JP969&sxsrf=AOaemvK6LtKm-reUcSqkol3KNGPls4TxBA%3A1632322030603&ei=7kFLYf2hJLKC1e8Ph7eNkAM&oq=dpi+tesseract+&gs_lcp=Cgdnd3Mtd2l6EAMYAjIGCAAQFhAeMgYIABAWEB4yBggAEBYQHjIGCAAQFhAeOgcIABBHELADSgQIQRgAUNUIWNUIYJQkaABwA3gAgAGvA4gBrwOSAQM0LTGYAQCgAQHIAQjAAQE&sclient=gws-wiz

@n0099
Copy link
Contributor

n0099 commented Mar 7, 2023

After update libtesseract-dev to 5.3.0, this warning will no longer be shown, perhaps now they will try to guess the dpi based on the size of characters' font in image: tesseract-ocr/tesseract#1702 (comment)

The current Tesseract release 5.0.0 tries to guess the correct resolution if there is no explicit information from the image file.

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