Menu

#2 How to Convert Android platform OCR into Text File

v1.0_(example)
open
nobody
5
2013-09-07
2012-08-02
Anonymous
No

In Recognizer demo for android we have OCR library detected images displayed in red color at top of the screen but variable result is always null or empty. Because of which it does not allow converting into String & text format. Please suggest way to achieve this as in standalone java application it is happening.

Discussion

  • Anonymous

    Anonymous - 2013-08-14

    I have the same issue. The bug is the moments.json file is not read correctly. It fails to recognize the first "Metric" line, then issues an exception, which ensures the metricMatcher has no metrics with which to recognize the input glyphs. Thus, nothing is matched.
    The trainer issues the json correctly, but the json errors when reading.
    I'm attempting to get the json read correctly.

     
  • Konstantin Pribluda

    could you be more specific? any logs? did you tried to debug?

     
  • Anonymous

    Anonymous - 2013-08-14

    So it looks like the culprit is JSONUnmarshaller, about line 85: Class clazz = method.getParameterTypes()[0];
    When "Metric" is scanned, clazz should be of MetricContainer, but it is Metric, an interface and not a class so there's no constructor method and thus the exception thrown.

     
  • Anonymous

    Anonymous - 2013-08-15
    Post awaiting moderation.
  • Anonymous

    Anonymous - 2013-08-16

    I've also discovered a bug in the trainer.java file. After training, there's a section on "perform image recognition to demonstrate sample quality". The following two lines always say the match is good:
    final Character result = match.getChr();
    if (result == match.getChr()) {

    the last line should be something like:
    if (result == expectedChar) {

    When I correct this and run my own sample files, I get matches 61 times out of 364 after 15 files of training. I'll try training many more files.

     
  • Martí Griera Jorba

    Hi,

    I detected the same problem, and as it was a bit tricky to understand what was wrong, I'll share it here. The project is using the jsonmarshaller-0.6.jar library. After looking at its source code (you can get it from http://grepcode.com/snapshot/repo1.maven.org/maven2/de.pribluda.android/jsonmarshaller/0.6/ ), I discovered that the class JSONUnmarshaller mainly tries to create class objects and assign them the values found in a JSON file. More concretely, in the line 227 of Recognizer.java:

    JSONUnmarshaller.unmarshallArray(jreader, MahalanobisClusterContainer.class)
    

    it expects to read an array of MahalanobisClusterContainer objects from the JSON file. Then, the JSONUnmarshaller tries to find setter functions by name for the attribute values found in the JSON files, and it extracts from the headers of the setter functions the type of the variables to be set. And here comes the problem. Since MahalanobisClusterContainer extends MetricContainer, there are 2 suitable setter functions to set a metric:

    public void setMetric(Metric metric)
    public void setMetric(MahalanobisDistanceCluster metric)
    

    And unfortunatelly, the JSONUnmarshaller founds first the first one. Then it assumes that the class is "Metric", and when it tries to create an object, it fails, as Metric is an interface and has no creator functions. All works fine if you force the JSONUnmarshaller to find the other function, as MahalanobisDistanceCluster (which extends AbstractBaseCluster which implements Cluster which extends Metric) is instanciable. You can do a dirty patch for this in many ways. I propose the following solution (which I tested and at least it works for our case) to patch the Json Marshaller library itself, aiming to be a bit more generic. It is simple, I modified the function getCandidateMethod of the JSONUnmarshaller, so that I don't allow it to find as candidates, setter methods with an interface parameter. Just chaged the line 317 of the file JSONUnmarshaller.java, it should be:

    if (method.getParameterTypes().length == 1 && name.equals(method.getName()) && !method.getParameterTypes()[0].isInterface())
    

    instead of:

    if (method.getParameterTypes().length == 1 && name.equals(method.getName()))
    

    Hope this helps!

     
  • Konstantin Pribluda

    Hi, Thanks for your research. I created this cluster container to evercome probem with JSON parsing - jsonmarshaller is really lightweight library to use on android, and has some drawbacks. You may use other marshalling libraries though.

    Dare to create pull request on github for Json Serialiser ?

    https://github.com/ko5tik/jsonserializer

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.