GithubHelp home page GithubHelp logo

Working on Mono about tesseract HOT 21 CLOSED

charlesw avatar charlesw commented on August 21, 2024
Working on Mono

from tesseract.

Comments (21)

charlesw avatar charlesw commented on August 21, 2024

That's certainly an option, I'll look into it next weekend if I have time.

from tesseract.

charlesw avatar charlesw commented on August 21, 2024

Can you see if this works now? You'll need to comment out all calls to WindowsLibraryLoader.LoadLibrary first.

from tesseract.

Gankov avatar Gankov commented on August 21, 2024

It is works on Windows and don't work on Linux.
I am not understand how it will work on Linux with current implementation. What do i need comment out?
If i will need write code that load linux library, that ok. I will try implement it after end work on using tesseract in my application at least for windows.
I think if wrapper library runs on linux, it need to load linux library from /usr/lib64/libtesseract.so.3.0.2
if it running on windows need to load dll.
I didn't write cross-platform wrappers before, and don't know how it should be implemented.

from tesseract.

charlesw avatar charlesw commented on August 21, 2024

Ok I understand, for now you'll need to comment out the loadlibrary routines I mentioned previously this is to prevent it loading the libs using the win32 libs. I'm also assuming that mono can resolve the tesseract libraries and get the right version. If you've got this far already and still having issues its likely either an x86 or x64 issue or the given method Isn't been invoked correctly by mono. Were you able to invoke the getversion method this might be a good way to tell if the library was loaded correctly.

from tesseract.

AndreyAkinshin avatar AndreyAkinshin commented on August 21, 2024

Hi, charlesw!

I think, the Mono support is a great feature. Maybe the following way will be useful:
http://dimitry-i.blogspot.ru/2013/01/mononet-how-to-dynamically-load-native.html
What do you think?

from tesseract.

charlesw avatar charlesw commented on August 21, 2024

Looks promising, do you want to give it a go?
On 22 May 2014 20:30, "Andrey Akinshin" [email protected] wrote:

Hi, charlesw!

I think, the Mono support is a great feature. Maybe the following way will
be useful:

http://dimitry-i.blogspot.ru/2013/01/mononet-how-to-dynamically-load-native.html
What do you think?


Reply to this email directly or view it on GitHubhttps://github.com//issues/23#issuecomment-43871475
.

from tesseract.

AndreyAkinshin avatar AndreyAkinshin commented on August 21, 2024

Yes, I will do it.

from tesseract.

AndreyAkinshin avatar AndreyAkinshin commented on August 21, 2024

Unfortunately, I could not find a beautiful solution based on the DllImport attribute because of Mono and Microsoft .NET Runtime have different algorithms that work with native libraries. So, I developed own approach: we can generate calls of native method on the fly by signatures from some interface. Please take, a look at my solution: https://github.com/AndreyAkinshin/DotNetRuntimeImplementer
If you like this approach, I can modify it to your needs.

from tesseract.

charlesw avatar charlesw commented on August 21, 2024

Looks good, I'd probably like to see the function delegates you create in
InteropRuntimeImplementer.InvokeMethod being cached.

Also how are you handling parameter and result Marshalling?

Also while I do realise that mono and .net have different algorithms for
loading unmanaged libraries I thought the dllimport technic would have
worked on both platforms provided the library name was the same which
should be the case since the extention is left off. What was the issue that
you ran into that prevented it from working?

Unfortunately, I could not find a beautiful solution based on the DllImport
attribute because of Mono and Microsoft .NET Runtime have different
algorithms that work with native libraries. So, I developed own approach:
we can generate calls of native method on the fly by signatures from some
interface. Please take, a look at my solution:
https://github.com/AndreyAkinshin/DotNetRuntimeImplementer
If you like this approach, I can modify it to your needs.


Reply to this email directly or view it on GitHub
#23 (comment).

from tesseract.

AndreyAkinshin avatar AndreyAkinshin commented on August 21, 2024

I'd probably like to see the function delegates you create in InteropRuntimeImplementer.InvokeMethod being cached.

What do you mean?

Also how are you handling parameter and result Marshalling?

I do it via IL commands. Please check out method RuntimeImplementer.ImplementMethods.

What was the issue that you ran into that prevented it from working?

There are several problems.
First: MS.NET Runtime used loaded in memory assemblies for resolving DllImport. Mono don't. So, approach with LoadLibrary don't work in Mono.
Second: let's consider an example. We have the x86 architecture. The tesseract wrapper says: “I want to use native method from DllImport["x86/libtesseract302.dll"]”. Mono says: “Ok”. The native libtesseract302 library says: “I want to use liblept168.dll for native needs”. Mono says: “I will look for liblept168.dll in the root direcory. Oops, there is no file ./liblept168.dll”. Unfortunately, even DllMap can't solve the problem with native dependences (anyway, I could not get to do it). So, the only way is load the target library handle, load the target method address (GetProcAddress) and explicitly use it. But explicitly using is a very ugly way. So, I generate the target logic on the fly with IL commands using signature from declared interface. The result code is very similar to this approach.

Sorry for my bad English. Please, feel free to ask any additional questions.

from tesseract.

charlesw avatar charlesw commented on August 21, 2024

Thanks for the quick response. All up looks like a very nice approach to
getting support for mono and dotnet in one assembly.

Do you want to have a look at adding this to this library? Let me know if
there is anything I can do to help.

Charles
On 16 Jul 2014 17:34, "Andrey Akinshin" [email protected] wrote:

I'd probably like to see the function delegates you create in
InteropRuntimeImplementer.InvokeMethod being cached.

What do you mean?

Also how are you handling parameter and result Marshalling?

I do it via IL commands. Please check out method
RuntimeImplementer.ImplementMethods.

What was the issue that you ran into that prevented it from working?

There are several problems.
First: MS.NET Runtime used loaded in memory assemblies for resolving
DllImport. Mono don't. So, approach with LoadLibrary don't work in Mono.
Second: let's consider an example. We have the x86 architecture. The
tesseract wrapper says: “I want to use native method from
DllImport["x86/libtesseract302.dll"]”. Mono says: “Ok”. The native
libtesseract302 library says: “I want to use liblept168.dll for native
needs”. Mono says: “I will look for liblept168.dll in the root direcory.
Oops, there is no file ./liblept168.dll”. Unfortunately, even DllMap
http://www.mono-project.com/Config_DllMap can't solve the problem with
native dependences (anyway, I could not get to do it). So, the only way is
load the target library handle, load the target method address (
GetProcAddress) and explicitly use it. But explicitly using is a very
ugly way. So, I generate the target logic on the fly with IL commands using
signature from declared interface. The result code is very similar to this
approach
http://dimitry-i.blogspot.ru/2013/01/mononet-how-to-dynamically-load-native.html
.

Sorry for my bad English. Please, feel free to ask any additional
questions.


Reply to this email directly or view it on GitHub
#23 (comment).

from tesseract.

AndreyAkinshin avatar AndreyAkinshin commented on August 21, 2024

Ok, I'll try. Can you give me Unix binary files for the native tesseract library and the native leptonica library? (x86 and x64 versions)

from tesseract.

charlesw avatar charlesw commented on August 21, 2024

If by Unix you mean a linux distro like Ubuntu I think you can just use the
package manager. The package is called tesseract-ocr.

E.g. http://packages.ubuntu.com/search?keywords=tesseract-ocr
On 17 Jul 2014 20:34, "Andrey Akinshin" [email protected] wrote:

Ok, I'll try. Can you give me Unix binary files for the native tesseract
library and the native leptonica library? (x86 and x64 versions)


Reply to this email directly or view it on GitHub
#23 (comment).

from tesseract.

AndreyAkinshin avatar AndreyAkinshin commented on August 21, 2024

Ok.

from tesseract.

AndreyAkinshin avatar AndreyAkinshin commented on August 21, 2024

Great news! My approach works with Tesseract. Now, I am preparing a pull-request for you. What branch should I use?

Also there is an issue about Linux support. It's about locale: we should use "LC_ALL=C" for normal work. In the other case, the native Tesseract library gives an error: Error: Illegal min or max specification!. You can read more about the issue here and here (look to the initialize_tesseract function). Do you now, how we can fix it from C# source code?

from tesseract.

charlesw avatar charlesw commented on August 21, 2024

Excellent, use the dev branch.

I'll have a look at the LC-ALL issue tomorrow.
On 18 Jul 2014 20:11, "Andrey Akinshin" [email protected] wrote:

Great news! My approach works with Tesseract. Now, I am preparing a
pull-request for you. What branch should I use?

Also there is an issue about Linux support. It's about locale: we should
use "LC_ALL=C" for normal work. In the other case, the native Tesseract
library gives an error: Error: Illegal min or max specification!. You can
read more about the issue here
https://code.google.com/p/tesseract-ocr/issues/detail?id=910 and here
https://github.com/zdenop/pyTesseractDemo/blob/master/pyTesseractDemo.py
(look to the initialize_tesseract function). Do you now, how we can fix
it from C# source code?


Reply to this email directly or view it on GitHub
#23 (comment).

from tesseract.

charlesw avatar charlesw commented on August 21, 2024

In regards to the LC-ALL issue you should be able to implement the
recommend workaround for 3.02 by calling setlocale. A quick search
indicates it lives in libc.so or similar.
On 18 Jul 2014 20:20, "Charles Weld" [email protected] wrote:

Excellent, use the dev branch.

I'll have a look at the LC-ALL issue tomorrow.
On 18 Jul 2014 20:11, "Andrey Akinshin" [email protected] wrote:

Great news! My approach works with Tesseract. Now, I am preparing a
pull-request for you. What branch should I use?

Also there is an issue about Linux support. It's about locale: we should
use "LC_ALL=C" for normal work. In the other case, the native Tesseract
library gives an error: Error: Illegal min or max specification!. You
can read more about the issue here
https://code.google.com/p/tesseract-ocr/issues/detail?id=910 and here
https://github.com/zdenop/pyTesseractDemo/blob/master/pyTesseractDemo.py
(look to the initialize_tesseract function). Do you now, how we can fix
it from C# source code?


Reply to this email directly or view it on GitHub
#23 (comment).

from tesseract.

AndreyAkinshin avatar AndreyAkinshin commented on August 21, 2024

Unfortunately, I found one more issue with my library. Now I don't have complete support of ref parameters. My solution works fine with Mono (Ubuntu and Windows), but it crashs on MS .NET Runtime. So, I need more time to improve my library. I think I will have a working solution on the next week.

from tesseract.

AndreyAkinshin avatar AndreyAkinshin commented on August 21, 2024

Great news! I developed new version of my library without relfection issues. Also now we can not worry about caching: I rewrote IL generation and now signature implements directly to native call. The pull-request will be soon.

from tesseract.

AndreyAkinshin avatar AndreyAkinshin commented on August 21, 2024

New version of the library: InteropDotNet
Pull-request: #107

from tesseract.

charlesw avatar charlesw commented on August 21, 2024

Merged changes into main dev branch and mono support will be in the next release. Thanks.

from tesseract.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.