NeutrinosPlatform / cordova-plugin-mobile-ocr

A cordova plugin that can accept image URI or Base64 data and returns the text present in the image as string without need for network. You can also try :- https://github.com/NeutrinosPlatform/cordova-plugin-ml-text
MIT License
49 stars 30 forks source link

ocr fail #13

Closed sdegunst closed 5 years ago

sdegunst commented 5 years ago

After use of cordova-plugin-document-scanner, I try to launch cordova-plugin-mobile-ocr (recText with returnType 2) and I only get the word "Exception". It seems to be a result of an error catched in line 100 in Textocr.java...

when I launch adb locat, I have the following crash log

04-05 19:13:17.707 28191 28191 D CordovaActivity: Incoming Result. Request code = 99 04-05 19:13:17.707 28191 28191 D CordovaInterfaceImpl: Sending activity result to plugin 04-05 19:13:17.712 28191 28191 D CordovaActivity: Started the activity. 04-05 19:13:17.712 28191 28191 D CordovaActivity: Resumed the activity. 04-05 19:13:17.714 28191 1199 W System.err: java.lang.StringIndexOutOfBoundsException: length=1; regionStart=0; regionLength=6 04-05 19:13:17.715 28191 1199 W System.err: at java.lang.String.startEndAndLength(String.java:298) 04-05 19:13:17.715 28191 1199 W System.err: at java.lang.String.substring(String.java:1087) 04-05 19:13:17.715 28191 1199 W System.err: at com.neutrinos.ocrplugin.Textocr$1.run(Textocr.java:72) 04-05 19:13:17.715 28191 1199 W System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 04-05 19:13:17.715 28191 1199 W System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 04-05 19:13:17.715 28191 1199 W System.err: at java.lang.Thread.run(Thread.java:818) 04-05 19:13:17.715 28191 1199 W CordovaPlugin: Attempted to send a second callback for ID: Textocr533608263 04-05 19:13:17.715 28191 1199 W CordovaPlugin: Result was: "Error" 04-05 19:13:17.725 28191 1199 W DynamiteModule: Local module descriptor class for com.google.android.gms.vision.dynamite not found.

sdegunst commented 5 years ago

I use the following version cordova-plugin-mobile-ocr : 2.0.0 cordova-plugin-document-scanner : 3.0.0

ChrisTomAlx commented 5 years ago

So returnType is no longer accepted from plugin version 2.x.x So the recText call should look like this. returnType is no longer required because all of them are returned as an object. textocr.recText(sourceType, uriOrBase, successCallback, errorCallback)

Usage Example

scan.scanDoc(1, onSuccess, onFail);

function onSuccess(imageURI) {
      textocr.recText(0, /*3,*/ imageURI, onSuccess, onFail); // removed returnType (here 3) from version 2.0.0
      // for sourceType Use 0,2 // 1,3,4 won't work
      function onSuccess(recognizedText) {
            //var element = document.getElementById('pp');
            //element.innerHTML=recognizedText;
            //Use above two lines to show recognizedText in html
            console.log(recognizedText);
            alert(recognizedText);
      }
      function onFail(message) {
            alert('Failed because: ' + message);
      }
}
function onFail(message) {
      alert('Failed because: ' + message);
}

Cheers, Chris Neutrinos

sdegunst commented 5 years ago

ok, I didn't notice... (and the description is not up to date on npmjs) I try this and give you a feed back.

sdegunst commented 5 years ago

OK, I get an object... could you give us some information about this object ?

ChrisTomAlx commented 5 years ago

Here you go. Added this and example objects as the last section in the github readme. The basic structure of the object is as follows :-

Cheers, Chris Neutrinos

ChrisTomAlx commented 5 years ago

Okay so I updated the npm readme as well (Plugin version 2.0.1). Closing this issue for now. Please reopen if you have questions related to this issue or create a new issue if you have a new question.

Cheers, Chris Neutrinos