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

textocr is not defined #11

Closed riadapsis closed 5 years ago

riadapsis commented 5 years ago

While using the following code and run it, I can capture the image with camera. But success function return the error "textocr" is not defined.

O.readText = function(){
        navigator.camera.getPicture(onSuccessText, onFailT, { quality: 100, correctOrientation: true });
    }
function onSuccessText(imageData) {
      textocr.recText(0, /*3,*/ imageData, onSuccessCam, onFailT); // removed returnType (here 3) from version 2.0.0
      // for sourceType Use 0,1,2,3 or 4
      // for returnType Use 0,1,2 or 3 // 3 returns duplicates[see table]
      function onSuccessCam(recognizedText) {
            var element = document.getElementById('pp');
            element.innerHTML=recognizedText;
            //Use above two lines to show recognizedText in html
            console.log(recognizedText);
            alert(recognizedText);
      }
      function onFailT(message) {
            alert('Failed because: ' + message);
      }
    }
    function onFailT(message) {
          alert('Failed because: ' + message);
    }

Screenshot_20190320-122249

If I change code from textocr.recText(0, /*3,*/ imageData, onSuccessCam, onFailT); to cordova.plugins.textocr.recText(0, /*3,*/ imageData, onSuccessCam, onFailT); then I got - Screenshot_20190320-123232

I am using Samsung J2 Prime with android version 6.0.1 (Plugin version 2.0.0)

Thanks in advance.

ChrisTomAlx commented 5 years ago

Hey @riadapsis

Your code seems to be working for me. Are you using some framework like ionic, angular, phonegap etc. over the cordova implementation ? Or are you directly creating a cordova project as cordova create myproject and then adding the plugin? If you are using frameworks like ionic then in the file you are using the plugin in you need to define the textocr object. declare var textocr;

Let me know if this was helpful!

If you could make a dummy project, recreate the issue, zip it and send it over, I could much more easily resolve the issue and get you to the solution.

Cheers, Chris Neutrinos

riadapsis commented 5 years ago

Hi @ChrisTomAlx , Many thanks for your quick answer. I am using phonegap. My project is already in live. My app need a new feature like ocr. So, I install the plugin through npm (intel xdk is my ide). But it's not working. With the same procedure I have already added many plugin like barcode scanner etc. At the top of js file I add the line var textocr; But I got Error: Uncaught TypeError: Cannot read property 'recText' of undefined in file:///android_asset/www/cordova.js at line 314 I am stuck with this.. Please help me out.

ChrisTomAlx commented 5 years ago

I tried getting the intel xdk ide to help you with the problem but it says they have discontinued it. Anyhow, I have a question for you.

  1. Don't you have to add plugin as phonegap cordova plugin add cordova-plugin-mobile-ocr via the cordova cli tool? (Atleast that is how I had to do it) Will doing npm install be enough?

  2. Also don't you have to remove platforms and re-add them for this to work? Could you check the config.xml of your project if the mobile ocr plugin is visible there ?

From what I have gathered I think it is an issue with the plugin not being installed. But I could be wrong!!

Cheers, Chris Neutrinos

riadapsis commented 5 years ago

Sorry for the late response... I have uploaded the software to my google drive - url

  1. xdk has a UI to add third party plugin from git/npm
  2. No confix.xml create at xdk. It gives a .zip file. I upload it to build.phonegap.com and got the desired apk.

You can download the file and see how they made the development too much easy!!! Waiting for your answer.

ChrisTomAlx commented 5 years ago

I will look into it and get back to you

Cheers, Chris Neutrinos

ChrisTomAlx commented 5 years ago

Okay so I did a build from the xdk ide.

if you unzip the zip file you received from the xdk ide, you will get a config.xml, can you check inside it if you have the textocr plugin ?

Cheers, Chris Neutrinos

ChrisTomAlx commented 5 years ago

Accidentally closed the issue. sorry!

indraraj26 commented 5 years ago

getting same error even though i have defined declare var textocr: any;

Error: ERROR Error: Uncaught (in promise): ReferenceError: textocr is not defined ReferenceError: textocr is not defined

ChrisTomAlx commented 5 years ago

Closing this issue since the solution for this has been shared here.

Thanks to @indraraj26 for sharing the solution

Cheers, Chris Neutrinos

karthi941111 commented 4 years ago

Hi..

$('#camScan').click(function(){
navigator.camera.getPicture(onSuccessCam, onFailCam, { quality: 50, correctOrientation: true }); });

        function onSuccessCam(imageData) {
            try{
                textocr.recText(0, /*3,*/ imageData, onSuccessRegc, onFailregc); 
                  function onSuccessRegc(recognizedText) {
                        alert(recognizedText);
                  }
                  function onFailregc(message) {
                        alert('Failed because: ' + message);
                  }
            }catch(err)
                {
                    alert(err);
                }
        }

        function onFailCam(message) {
                  alert('Failed because: ' + message);
        }

used the above code for implementing OCR am getting error as ReferenceError:tectocr is not defined plz help me to sort it out

In Config.xml

    <plugin name="cordova-plugin-mobile-ocr" spec="~3.1.1" />