Multi threading OpenALPR on Android

471 views
Skip to first unread message

Matic Odar

unread,
Feb 18, 2016, 7:42:29 AM2/18/16
to OpenALPR
Hey Matt,

I made an android app that takes frames from the camera and does recognize on them. To get more frames I start multiple parallel threads (number defined by number of cores - 1). At first I created an Alpr instance for each separate frame. So everytime there is a new frame I check if there is less than maximum number of threads and start a new one and create a new alpr instance. Then, to get rid of the continuous reading of config and initializing trained data, I create max threads at start and pause them when they get results from alpr until a new frame is avaliable. That way I have only 1 Alpr initialization per thread at start. But after running the app for a while, a fatal signal is thrown and app crashes. I've tested this a bit and this happens in the time when there is a valid plate and ocr is running (can happen at any point).

Is there anything in the OCR that might be using some kind of shared resource that gets locked and another thread fails when it tries to use the same resource?

Thanks bud

Matt

unread,
Feb 18, 2016, 8:27:59 AM2/18/16
to OpenALPR
Matic,

Yes, the issue, as you guessed, is the Tesseract library.  Everything else is fully thread-safe.  You can see the issue here with Tesseract 3.01 announcement: https://groups.google.com/forum/#!topic/tesseract-ocr/q_WPeqeAaEE
  • Thread-safety! Moved all critical globals and statics to members of the appropriate class. Tesseract is now thread-safe (multiple instances can be used in parallel in multiple threads.) with the minor exception that some control parameters are still global and affect all threads.
The qualifier there being you can use multiple instances on multiple threads, but not one instance across threads.  Therefore it's not *actually* thread-safe.  

Right now it works fine if you create an instance of OpenALPR for each thread that is not touched by other threads.  If you try and reuse the object across threads it has problems.

Matic Odar

unread,
Feb 18, 2016, 1:25:46 PM2/18/16
to OpenALPR
Thanks for the quick reply,

I use the Tess-Two repository to build the Tesseract library, which uses Tesseract 3.05.

I do create an OpenALPR instance for each thread separately.

Is it possible that Tesseract keeps working after it returns results? I attached the source code for the thread, and the interesting part is in the run() function. 

If I remove the code between the two long comments, it throws the error after some time. Memory usage is the same in both cases. Can you see anything that would cause problems?

Thanks
ProcessThread.java

Mathias Rönnlund

unread,
Feb 12, 2017, 2:58:52 PM2/12/17
to OpenALPR
Matic,

Did you ever get this working properly? If you have some working code, would you mind sharing it?
Reply all
Reply to author
Forward
0 new messages