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

Application crashing while disposing Pix.Create object #739

Open
saikumarkavali1 opened this issue Apr 5, 2024 · 5 comments
Open

Application crashing while disposing Pix.Create object #739

saikumarkavali1 opened this issue Apr 5, 2024 · 5 comments

Comments

@saikumarkavali1
Copy link

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
Copy link
Owner

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
Copy link
Author

saikumarkavali1 commented Apr 8, 2024

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.

  • For File1: pixOrientDetect() is returning expected confidence values for 90° and 180° rotated.
  • For File2: pixOrientDetect() is returning wrong confidence values for 90° rotated and file is not rotated. If I use same method for second time, it is rotating properly. But 180° rotation confidence values are expected and rotation is proper.

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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

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

2 participants