DanBloomberg / leptonica

Leptonica is an open source library containing software that is broadly useful for image processing and image analysis applications. The official github repository for Leptonica is: danbloomberg/leptonica. See leptonica.org for more documentation.
Other
1.77k stars 389 forks source link

Application crashing while disposing Pix.Create object #739

Open saikumarkavali1 opened 6 months ago

saikumarkavali1 commented 6 months ago

Hi @DanBloomberg ,

I'm using 1.81.1 with VS2022 on Windows 11 for rotating the file according to the text.

While disposing the Pix.Create object, my application has crashed. On checking the logs, I found the below exception. "An attempt was made to perform a read or write operation on protected memory. It is possible that other memory is corrupted"

using (Pix pix = Tesseract.Pix.Create(pixPtr))
{
    using (Pix RotatedImage = RotateImage(pix))
    {
        if (RotatedImage != null) RotatedImage.Save(tempFileName);
        if (pixPtr != IntPtr.Zero) pixPtr = IntPtr.Zero;
    }
}

Note: This crash is observed mostly in files with Japanese text.

Below is the attached sample file for which this issue is observed. File.zip

I appreciate a quick response. Thanks in advance.

DanBloomberg commented 6 months ago

Note that the pix returned from pixCreate() is a pointer to a pix struct.

If that doesn't solve your problem, I can't help you, because I do not "speak" C#, and don't know anything about leptonica getting converted into a C# library. I can assure you that the problem is NOT in leptonica: it is either in the conversion to C# or in your code using it.

saikumarkavali1 commented 6 months ago

Thank you @DanBloomberg, your assumption was right. I'm able to control the application crashing as per your comments.

Now, I got the problem in getting the proper confidence values from pixOrientDetect().

I have two sample files with 90° and 180° rotated, I used pixOrientDetect() to get the up and left confidence so that rotate the file correctly.

How to use pixOrientDetect(pixs, out pupconf, out pleftconf, 0, 0) in such a way to get the proper confidence values.

I appreciate a quick response. Thanks in advance.

Files are attached for the reference. Sample.zip

DanBloomberg commented 6 months ago

I'm surprised it got anything right for File1. The orientation function uses ascenders and descenders from the xheight region of the text line, which you find in Roman text, not kanji.

As for File2, that's handwritten and is not expected to work properly for any type face.

saikumarkavali1 commented 5 months ago

Thank you for the reply.

Here is the another file which is failing to rotate. It doesn't have any handwritten but failing to get expected confidence values. 取引先名刺.zip

This file resolution is 300, I used pixScale() to scale it down and ran pixOrientDetect() on it. Output is not expected one.

DanBloomberg commented 5 months ago

Again, this application only works for roman text characters that have ascenders and descenders. So it doesn't even work for numbers and ALL CAPS. See comments in the file flipdetect.c