halkar / Tesseract.Xamarin

Tesseract OCR wrapper for Xamarin
MIT License
121 stars 40 forks source link

Tesseract does not reference well in the PCL project. #34

Closed bnikollov closed 7 years ago

bnikollov commented 7 years ago

I have some troubles with Xamarin.Tesseract in Xamarin.Forms. I think it's not referenced well in the PCL project. There are the references in my PCL project: https://s10.postimg.org/gv93ztqrt/tesserr.png This is the exception I get: https://s3.postimg.org/awvrxj143/tesserr.png

halkar commented 7 years ago

@bnikollov can you share your project?

bnikollov commented 7 years ago

Hi, @halkar I am sorry this was not a Tesseract exception, it was from the xam.plugin.media. But I try to run this project (your sample Tesseract.Nuget.Test) and it throws another exception when I press the button load image. http://imgur.com/a/f7p62

halkar commented 7 years ago

@bnikollov no worries.

Can you give me a stack trace for the new issue?

bnikollov commented 7 years ago

@halkar I handled this exception too. Now the project runs on iOS simulator, but on Android when resolving the tesseract api throws an exception "Autofac.Core.DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = TesseractApi (ReflectionActivator), Services = [Tesseract.ITesseractApi], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Tesseract.Droid.TesseractApi' can be invoked with the available services and parameters:

Cannot resolve parameter 'AssetsDeployment assetsDeployment' of constructor 'Void .ctor(Context, AssetsDeployment)'. (See inner exception for details.)"

Do I have to pass some parameters here: containerBuilder.RegisterType TesseractApi ().As ITesseractApi ();

and if yes what should I pass. I try to pass (ApplicationContext, Tesseract.Droid.AssetsDeployment.OncePerInitialization), but intellisense says I should pass a string instead ApplicationContext.

halkar commented 7 years ago

What do you use for DI? It should be instance of Context and AssetsDeployment parameter.

bnikollov commented 7 years ago

I use Autofac for now. Which you have used in the project. This is just for testing Tesseract. Later I will put this in other project where the DI is with Unity. In your sample project you do not pass any parameters nether for iOS nor for Android. Can you show me how to pass them in the right way?

halkar commented 7 years ago

In Autofac initialisation should be something like this:

containerBuilder.Register (c => this).As<Context> ();
containerBuilder.RegisterType<TesseractApi> ()
                .As<ITesseractApi> ()
                .WithParameter ((pi, c) => pi.ParameterType == typeof(AssetsDeployment),
                (pi, c) => AssetsDeployment.OncePerInitialization);

In this case I initialise it in my MainActivity class.

bnikollov commented 7 years ago

Thanks, that worked and thank you for your time @halkar !