leptonica
leptonica copied to clipboard
Application crashing while disposing Pix.Create object
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.
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.
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
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.
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.
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