Phreak87 / LeptonicaSharp

Full featured wrapper for leptonica 1.77.0
Other
8 stars 5 forks source link

System.AccessViolationException during pixOrientDetect #65

Closed CanadianHusky closed 4 years ago

CanadianHusky commented 4 years ago

Hello,

The following minimalistic code, inspired from this C++ version (https://stackoverflow.com/a/31906060) crashes at the marked line and I cannot figure out what I am doing wrong. The goal is to do orientation detection as fast as possible Is anyone kind enough to provide an opinion what could be done ? I am using the 64 bit version LeptonicaSharp-master\LIB_LEPT\X64\leptonica-1.77.0.dll and the wrapper seems to load the native DLL fine. Thank you veru much

An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module. Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

        Dim mypix As New LeptonicaSharp.Pix("c:\temp\input.png")
        Dim upconf1(), leftconf1() As Single
        Dim fpixs As Pix = _AllFunctions.pixConvertTo1(mypix, 130)
        fpixs.Display() 'Display on screen is OK. Thresholding worked fine

'CRASH HERE
        _AllFunctions.pixOrientDetect(fpixs, 1, upconf1, leftconf1, Enumerations.DebugOnOff.DebugOff) 

        mypix.Dispose()
        fpixs.Dispose()
Phreak87 commented 4 years ago

Upconf1 and leftconf is not an array ... Dim upconf1, leftconf1 As Single

Additionally move the Parameters in the right Order:

    _AllFunctions.pixOrientDetect(fpixs, upconf1, leftconf1, 1, Enumerations.DebugOnOff.DebugOff)

Please try and Close this issue

CanadianHusky commented 4 years ago

There seems to be some sort of confusion with the wrapper library, or there are other versions floating around.

https://nugetmusthaves.com/Package/LeptonicaSharp the package from this link is version 1.77.0.1. When linked in a Project, it creates the following image

with this wrapper _All does not exist in the Leptonica Namespace, but _AllFunctions exists instead

I have now compiled the wrapper from the source using the repo at https://github.com/Phreak87/LeptonicaSharp/ and indeed the behaviour is different Observation: The old library has very detailed (helpful) xml documentation during intellisense. The new one does not.

I converted the 2 parameters to single data type and adjusted the parameter order the way the wrapper requires them. The test project does not compile without those correct data types anyways.

Now I am able to execute the code correctly and some non-zero values for upconf1, leftconf1 are returned without an error.

However a new problem arises - the expected result is not happening.

  ```
    Dim pix1 As New Pix("c:\temp\cimg_BR-90.png")
    Dim fpixs As Pix = _All.pixConvertTo1(pix1, 130)
    Dim upconf1, leftconf1 As Single
    Dim pix2 As Pix = _All.pixOrientCorrect(fpixs, 0, 0, upconf1, leftconf1, 0)
    pix2.Display()
    'cleanup
    pix1.Dispose()
    pix2.Dispose()

There are no debugger or code errors anymore, however this test image is not rotated correctly as expected

Is there anything that can be done about that ? Thank you for the prompt response. The amount of work in the wrapper is impressive. Well done.

image

Phreak87 commented 4 years ago

Thank you,

the function works fine. i think your image have to less usable information to rotate. try it with other pictures (e.g. normal book page) and it will work as expected.

Phreak87 commented 4 years ago

Oh and ... Use the Library you Compiled ... The nuget is not up- to-date