Git Product home page Git Product logo

tesseract.xamarin's Introduction

Xamarin.Tesseract

Xamarin.Tesseract is a wrapper for Tesseract OCR library. For Android tess-two is used and for iOS implementation from gali8 (v.4.0.0) is used.

Documantation

Blog post

Utilisation

Best way to use Xamarin.Tesseract is to add Nuget package to your project.

//Android
TesseractApi api = new TesseractApi (context, AssetsDeployment.OncePerVersion);
//iOS
TesseractApi api = new TesseractApi ();
await api.Init ("eng");
await api.SetImage("image_path");
string text = api.Text;

You will also need tessdata files for the languges you need. In Android application tessdata folder should be in your assets directory and files should be marked as AndroidAssets. In iOS project testate should be in Resources and files should be marked as BundleResource. You can add more than one language in the same folder. In this case use "+"-separated list of languages to initialise TesseractApi.

License

Tesseract.Xamarin is distributed under the MIT license (see LICENSE). Tesseract, maintained by Google (http://code.google.com/p/tesseract-ocr/), is distributed under the Apache 2.0 license (see http://www.apache.org/licenses/LICENSE-2.0). Tesseract OCR iOS is distributed under MIT license (https://github.com/gali8/Tesseract-OCR-iOS/blob/master/LICENSE.md). tess-two is distributed under Apache 2.0 license (https://github.com/rmtheis/tess-two/blob/master/COPYING).

tesseract.xamarin's People

Contributors

halkar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tesseract.xamarin's Issues

Error on Init()

I'm getting an exception when calling Init()

image

I have included the tessdata folder and set the content type for all the files as per the instructions.
Any ideas?

Problem on Galaxy S6 Edge

Hi,

I've got a crash when I initialise my TesseractAPI :
dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.myapp/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libpngt.so"

Any idea?

0.3.1 breaks, have to go back to 2.1.0

Tried to update from 2.1.0 to 0.3.1, the application crash with unhandled exception.
Using the latest Xamarin forms and Xlabs.
Have to goback to 2.1.0.

Cheers,
Reinhard Sua

Tesseract iOS Still working ?

Does these Tesseract bindings / nugget still work on iOS or am I doing something wrong ?

I am finding it hangs forever on trying to process an image.
I have tried using different TessDatas but never had any success.

I am attaching self contained test
Tess.zip

Any pointers would be gratefully recieved

iOS crash on Init()

I am having trouble with await _tesseractApi.Init(“eng”);

I have tried everything but this silently kills the app.

In the Application output there is only one line that may reference the issue: actual_tessdata_num_entries_ <= TESSDATA_NUM_ENTRIES:Error:Assert failed:in file tessdatamanager.cpp, line 53

The file is definitely added: <BundleResource Include="Resources\tessdata\eng.traineddata" />

Android: Bitmap sampled

When using SetImage, the bitmap is in SampleSize (value 4) when using byte[] or path to image, but not on Stream.
Could you consider making this sample size an option (even if default value is 4) and give the opportunity to get the sample size (when we retrieve coords, we want to know how to transform them to get back coords to our original image)

TesseractApi not initialized

TesseractApi _api = new TesseractApi (this, AssetsDeployment.OncePerInitialization);
_api.Init ("eng");

when i debugging code and check _api intialized value it is returning false

I'm using the sample code and it hangs

When the SetImage method is called the operation never ends. The proress is not being updated. Is there an what is maximumRecognitionTime default? Do you know what might be happening?

Not getting correct data string in Xamarin.iOS and Xamarin.Android

I have used Tesseract OCR for scanning the receipts and fetching the data from the receipts. But the output string I get is not even in readable format.

img_0885

Following is the output string I get:

4
a
£355 5
S" 1
? k ,
4?,“ ,
n5, _ g '
.~ :' «
I, .
.

Need help to get correct data formatted string.

Android too Slow OCR

Hi.

I have successfully implemented the OCR on Android Xamarin.

I have to wait 78 Seconds only to get the result for this image ( https://i.imgur.com/ZYjUEQz.jpg ) and I do not think this is fine.

The result is fine but the time processing is soo long.

Any suggestion or advice would be much appreciated.

SetWhitelist throws a NullReferenceException

First all thanks for your amazing work... It's really impressive what you did.
With latest version from Nuget SetWhitelist throws a NullReferenceException.

Code sample:

TesseractApi api = new TesseractApi();
api.SetWhitelist("ACDFMN123456789");

Tesseract.Droid.TesseractApi.Init hangs

Started from Xamarin default Android app template, just added the tessdata files for English and called Init method, but execution hangs on Init method....

public class MainActivity : Activity
    {
        int count = 1;

        Tesseract.Droid.TesseractApi ocrApi;

        protected override void OnCreate (Bundle savedInstanceState)
        {
            base.OnCreate (savedInstanceState);

            this.ocrApi = new Tesseract.Droid.TesseractApi(this,
                Tesseract.Droid.AssetsDeployment.OncePerVersion);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button> (Resource.Id.myButton);

            button.Click += delegate {
                button.Text = string.Format ("{0} clicks!", count++);
            };

            var result = this.ocrApi.Init("eng").Result;
        }
    }
}

image

Here's the debugger output (last part):
[TesseractApi] Copy assets to /storage/emulated/0/Android/data/com.companyname.labelscanner/files
Thread started: #2
Thread started: #3
[Mono] [0x7f58a19450] worker starting
Thread started: #4
[Mono] [0x7f58814450] worker starting
[Mono] DllImport attempting to load: '/system/lib64/libc.so'.
[Mono] DllImport loaded library '/system/lib64/libc.so'.
[Mono] DllImport searching in: '/system/lib64/libc.so' ('/system/lib64/libc.so').
[Mono] Searching for 'gettid'.
[Mono] Probing 'gettid'.
[Mono] Found as 'gettid'.
Thread started: #5
[Mono] [0x7f585fc450] worker starting
[Mono] [0x7f58a19450] hill climbing, change max number of threads 8
[Mono] [0x7f58a19450] worker finishing
Thread finished: #3
Thread finished: #2
[Mono] [0x7f58814450] worker finishing
Thread finished: #4
Thread finished: #5
[Mono] [0x7f585fc450] worker finishing

Application gets stuck after _api.SetImage(...) function invokation

Hello,
I am writing an app for android, in which I want to make simple character recognition. Xamarin.Tesseract nuget gets initialized, and then when _api.SetImage(...).Wait(); invoked, my app gets stuck and can't go farther. I tried to invoke that function with different parameters, Firstly copied bitmap content to a stream on some ways and then pass it(both as a stream and byte array). I tried also a version of this function where path is required(provided also good path, and bad path) - both resulted with endless wait.
Could you help me?
Thanks.

SetRectangle clearing all results and not returning any

Hi,

I'm currently using the lastest version of Tesseract.Xamarin in a Xamarin Forms project, only targeting the Android platform at the moment.

When I call the SetRectangle method, after successfully calling the SetImage method (checked with a boolean value after calling the method with await), the Text property keeps the original text it had after setting the image, and the Results property returns an empty collection no matter the page iterator level I pass to it.

Thanks in advance for checking this out!

Tesseract 4.0???

Is there any plans to upgrade this package to Tesseract 4.0?

Good job on the package it works great for me.

Could not find Tesseract.iOS

Hello, i've installed your Nuget Package in my solution. I could now find Tesseract.iOS so I can register the type TesseractAPI( which it doesn't recognise) in the container builder.
screen shot 2015-12-22 at 17 13 45

Rectangle.Box coords are invalid

It seems that GetBoundingBox on a Result (from TessBaseApi) returns box coords as left, top, right, bottom whereas when creating the Rectangle, coords are used as left, top, width, height...

using in PCL project

Hello.
I need to use it in PCL based project ( Android specifically ( iOS is not needed atm ) ) ( Forms is not a viable option atm ), but I cant even add it to using clause by some reason unknown disregarding i've installed it.
Is it working in PCL projects at all, and if it does - please post a small sample and description how to make it works.

Application crash on IOS9

Hi,

I'm currently building an OCR app and I use Xamarin.Tesseract for IOS. When I use my camera preview screen and send data to tesseract using Recognize function the application just shut down 20 seconds later. In logs there's memory warnings, any idea about where it can come from ?

Here is a code sample from the part that might be "bugging":
class DataOutputDelegate : AVCaptureVideoDataOutputSampleBufferDelegate {

        private TesseractApi api;
        private OcrController controller;
        private volatile bool processing;

        public DataOutputDelegate(OcrController controller) {
            this.controller = controller;
        }

        public async override void DidOutputSampleBuffer (AVCaptureOutput captureOutput, CMSampleBuffer sampleBuffer, AVCaptureConnection connection)
        {
            Console.WriteLine ("Try processing :: ");
            try {
                if(!processing) {
                    var image = ImageFromSampleBuffer (sampleBuffer);

                    if(api == null) {
                        api = new TesseractApi();
                    }

                    if(api != null && image != null) {
                        Console.WriteLine ("Processing :: ");
                        TesseractUtils.Instance.Configure(api);
                        processing = true;
                        await api.Recognise(image); /// this hangs 
                        processing = false;
                        image.Dispose();
                        Console.WriteLine ("end processing :: ");
                    }
                }
            } catch (Exception e){
                Console.WriteLine (e);
            } finally {
                sampleBuffer.Dispose ();
            }
        }

        UIImage ImageFromSampleBuffer (CMSampleBuffer sampleBuffer)
        {
            // Get the CoreVideo image
            using (var pixelBuffer = sampleBuffer.GetImageBuffer () as CVPixelBuffer) {
                // Lock the base address
                pixelBuffer.Lock (0);
                // Get the number of bytes per row for the pixel buffer
                var baseAddress = pixelBuffer.BaseAddress;
                int bytesPerRow = (int) pixelBuffer.BytesPerRow;
                int width = (int) pixelBuffer.Width;
                int height = (int) pixelBuffer.Height;
                var flags = CGBitmapFlags.PremultipliedFirst | CGBitmapFlags.ByteOrder32Little;
                // Create a CGImage on the RGB colorspace from the configured parameter above
                using (var cs = CGColorSpace.CreateDeviceRGB ()) {
                    using (var context = new CGBitmapContext (baseAddress, width, height, 8, bytesPerRow, cs, (CGImageAlphaInfo)flags)) {
                        using (CGImage cgImage = context.ToImage ()) {
                            pixelBuffer.Unlock (0);
                            return UIImage.FromImage (cgImage);
                        }
                    }
                }
            }
        }

        void TryDispose (IDisposable obj)
        {
            if (obj != null)
                obj.Dispose ();
        }
    }
}

Thanks !

Xamarin.Mac?

Any chances for Xamarin.Mac support? While I have succeeded in directly referencing .dll files from some packages that don't declare Xamarin.Mac support to make them work, as this package uses iOS Objective C library behind I guess it can't work on the Mac right now?

Having an issue with Byte[] input.

So my big idea is to try and capture frames from camera preview, and do OCR on the fly!

However when I pass in the byte array for the current frame:

                await _Api.SetImage(imageBytes);

It essentially hangs and doesn't return.

Does this Byte array need to be encoded before I pass it in? Any ideas on why it might hang?

My code is doing this:

            _Camera = Android.Hardware.Camera.Open();          
            _Camera.SetPreviewCallback(this); // the call back method is OnPreviewFrame, below.
            _Camera.StartPreview();      
...      
        public void OnPreviewFrame(byte[] data, Android.Hardware.Camera camera)
        {
            // data is the bytes representing the current frame.
            var text = GetText(data).Result;
        }
        public async Task<string> GetText(byte[] imageBytes)
        {
            // todo: call web api, send image, and get back text.
            try
            {
                EnsureInitialised();
                await _Api.SetImage(imageBytes); /// this hangs
                // await api.SetImage(imagePath);
                string text = _Api.Text;
                return text;          
            }
            catch (Exception ex)
            {
                throw;
            }     
        }
    }

Any help or advice is much appreciated.

Progress not being called

Greetings Halkar.

I really like your wrapper.

I am trying to use Progress Event, but it never gets called.

Can you help me?

Couldn't find "libpngt.so" on real Device

I'm trying to check a bitmap with the following code:

TesseractApi tessApi = new TesseractApi(context, AssetsDeployment.OncePerVersion);
await tessApi.Init("jpn");
await tessApi.SetImage(bitmapData);

and everything is working fine on an emulator, but after I tried to test it on a Samsung Galaxy S6 I got the following error:

dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/project.svgtest.svg_test-
1/base.apk"],nativeLibraryDirectories=[/data/app/project.svgtest.svg_test-1/lib/arm64, /vendor/lib64, 
/system/lib64]]] couldn't find "libpngt.so"

Google just finds a few similar cases where they recommended to rebuild Tesseract so when I understand it right it seems to be still an issue even when the same report was closed already.

Using Xamarin 4 with Xamarin Studio on a Mac.

Continually calling Api.Text in a loop - eventually crashes.

My algorithm does this:

  1. Initialises the API
  2. Begins an endless loop with the body:
                           _Api.SetImage(filePath)
                            .ContinueWith((t) =>
                            {
                                RunOnUiThread(() =>
                                    {
                                        _OcrText.Text = _Api.Text;
                                    });
                            });

After a few seconds of execution, there is an exception tfrom within the _Api.Text method. Do you have any existing test coverage for this scenario - i.e one that calls _API.Text many times on the same API instance?

HOCR support

Hello,

At this point this project does not support the HOCR function. ( on Android ). Tess Two has implemented this somewhere in the past, is it possible that the package could receive an update?

Luke

AssemblyVersionInfo.cs is missing

Perhaps AssemblyVersionInfo.cs is missing from the repository.Could you please rectify.I getting below errors

Severity Code Description Project File Line Suppression State
Error Source file 'C:\tesseract-master\src\Tesseract.Tests.Console..\AssemblyVersionInfo.cs' could not be found. Tesseract.Tests.Console C:\tesseract-master\src\Tesseract.Tests.Console\CSC
Error Source file 'C:\tesseract-master\src\Tesseract..\AssemblyVersionInfo.cs' could not be found. Tesseract C:\tesseract-master\src\Tesseract\CSC
Error Source file 'C:\tesseract-master\src\Tesseract.Tests..\AssemblyVersionInfo.cs' could not be found. Tesseract.Tests C:\tesseract-master\src\Tesseract.Tests\CSC

Pre Processing Photo

Hello,

I would like to know if there's any way to pre process the photo, by applying a grayscale filter and adjusting contrast, brightness, clip, saturation and other things like this.

Thanks.

Not working

Even using your test projects, only garbage is returned. Not only that, it takes well over 5 minutes, at least, to process an image. Only when taking an image directly from the camera or an image that was taken from the camera and loaded from the library. However, images downloaded from the web are read in just fine. Would this be a problem with the camera?

Init is returning false.

Hi @halkar ,
I am using it in Xamarin Forms application using DependencySevice. In Android, I have added language files in tessdata under Asset but Init is always returning false. I tried language files from your source (https://github.com/halkar/Tesseract.Xamarin/tree/master/Tesseract.Forms.Test/tessdata) and also tried file from (https://github.com/tesseract-ocr/tessdata/blob/master/eng.traineddata) but same result.

In DependencyService implementation class under Android I have something like this
TesseractApi api = new TesseractApi(Android.App.Application.Context, AssetsDeployment.OncePerVersion); var isInitialized = await api.Init("eng");
isInitialized is always false. Attach is my solution structure screenshot
untitled

Build and run the project Tesseract.Nuget.Test pop below error. Any idea?

Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Context)' on type 'TesseractApi'. ---> dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.tesseract.nuget.test-1/base.apk"],nativeLibraryDirectories=[/data/app/com.tesseract.nuget.test-1/lib/arm64, /system/fake-libs64, /data/app/com.tesseract.nuget.test-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64, /system/vendor/lib64, /product/lib64]]] couldn't find "liblept.so" (See inner exception for details.)

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.