How to integrate tesseract OCR with Cordova/Phonegap app - javascript

Im trying use tesseract OCR with my app and by instructions posted here
http://scn.sap.com/community/developer-center/front-end/blog/2015/05/15/create-an-ocr-android-app-with-cordova-and-tesseract
several times I followed the instructions but with no success.When im inspecting code with Google Chrome Dev console thru the WebVieW it give me
Uncaught SyntaxError: Unexpected token }
in file tesseractPlugin.js:11
thats located somewhere in
file:///android_asset/www/plugins/com.tesseract.phonegap/tesseractPlugin/tesseractPlugin.js
and
Uncaught Error: Module com.tesseract.phonegap.tesseractPlugin.TesseractPlugin does not exist.
in cordova.js:1431
witch i think means the cordova cant find the plugin but i dont know why.I think it's something with the version of Cordova and its access to plugins
its frustrating because there are no other options on the web and i dont know how to write my own cordova plugin.
I would also like to add that I created the project exactly as instructed to avoid the mistakes and over I have found that it is not possible to download the plugin by git from
https://github.com/engzhaowei/Tesseract-phonegap-android-example/tree/master/plugins/com.tesseract.phonegap.tesseractPlugin
so i downloaded full package and fetch plugin from
C:\xxx\plugins\com.tesseract.phonegap.tesseractPlugin

There is tessaract js http://tesseract.projectnaptha.com/
which is a javascript library and you can use it and will work for phonegap its very easy to implement.
Just reference the cdn script in the header and call the code snippet it should work. Be warned actress is slow.
<script src='https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js'></script>
var myimage = document.getElementById("largeImage").src;
Tesseract.recognize(myimage)
.then(function(result){
// console.log(result);
document.getElementById("textarea1").value = result.text; // assign results to a textbox

Related

Unable to load a js framework while the authors demo works without problems

I'm trying to use formio and a 3-rd party framework formio-export but I'm having trouble getting started.
The author provided a sample of the framework on his github page. Demo can be found here.
I've tried to recreate a simple demo using HTML/JS.
I was able to create the form, load a submission on demand, but I'm unable to get the print functionality working. When I press the print button, I get the error:
Uncaught ReferenceError: FormioExport is not defined
at HTMLButtonElement. (:47:21)
at HTMLButtonElement.dispatch (index.js:3)
at HTMLButtonElement.elemData.handle (index.js:3)
A fiddle for your convenience.
I would expect the formio-export to 'just work' once the script tag is added but maybe it requires some additonal configs?
You can't use it in the browser directly. You must use node in order to import the module
import FormioExport from 'formio-export';
and then use
npm run build
to make a browser bundle (as explained in the github page).

Using AWS.cloudSearch with javaScript

I'm trying to use AWS cloudSearch on my site, and I'm missing something fundamental. I've had no luck finding a working example.
In my HTML head I've included the SDK. per: http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/browser-intro.html
<script type="text/javascript" src="https://sdk.amazonaws.com/js/aws-sdk-2.0.31.min.js"></script>
Then in my script tag I have this snippet (with my creds, not the ones shown here). I used hard coded creds for my testing per: http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/browser-configuring.html
var s3 = new AWS.S3({region: 'ap-southeast-2', maxRetries: 15});
AWS.config.update({accessKeyId: 'akid', secretAccessKey: 'secret'});
console.log(AWS);
//
var cloudsearch = new AWS.CloudSearch();
When it tries to execute the last line javaScript tells me: Uncaught TypeError: undefined is not a function
I've been unable to find a demo, example or tutorial. The docs don't even have working examples.
Can you help?
Thank you for your time.
That error is saying it doesn't find reference to cloudsearch when you are calling the new AWS.Cloudsearch().
The script you reference doesn't appear to have a reference to cloudsearch api. I think you need to build it out like they specify in Building the SDK for Use in the Browser.
For kicks I replicated the error you received, then did a browser build as specified by the link above. It worked.
Upon further investigation after looking through the libraries. I think you probably want to use CloudSearchDomain to issue searches to a given domain setup within cloudsearch.
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudSearchDomain.html
The other cloudsearch library is all administrative/setup related to Search domain creation and other administrative types of objects. Looks like there are some issues with CORS/setup for cloudsearch in general so if you want to issue this straight from the browser might be a bit tricky.
The most common way to get around the CORS issue is to use a proxy.
The easiest way to play around with search from the browser\local is using a form, as suggested here.
Amazon CloudSearch query
<form action="https://$YOURSEARCHDOMAIN/2013-01-01/search" method="get">
<label>Search: <input name="q" /></label>
<input type="hidden" name="q.parser" value="simple" />
<button type="submit">Search</button>
</form>
above solution is pretty much cut and paste\play, works like the AWS cloudsearch console, and returns the json to the browser. Not sure if you can incorporate suggests without the api directly. You will need to open up your access policy to work, I believe.
I tried a variety of access policies and various tricks to get around the CORS issue, all no dice.
You actually need the CORS plugin for chrome to make this work properly.
Created an angularjs project that demos this and added to git hub. You need CORS-anywhere to route properly to the domain.
https://github.com/tkntobfrk/amazon-cloudsearch-angular
project uses suggesters to search domain data and populate the input field with autocomplete data. Uses bootstrap.ui typeahead.

Apache Cordova ContactFind

Okay so for the past two days I've been struggling to get my first Cordova/Eclipse project up and running. I'm trying to retrieve the contacts from my phone, using the ful sample code provided on the Apache Cordova website. http://cordova.apache.org/docs/en/2.5.0/cordova_contacts_contacts.md.html
But it's not working. I keep getting this error: "Uncaught ReferenceError: ContactFindOptions". And yes, I have included the needed plugin using the Cordova CLI. I also tried adding it manually, to no avail.
// Cordova is ready
function onDeviceReady() {
// find all contacts with 'Bob' in any name field
var options = **new ContactFindOptions()**;
options.filter="Bob";
var fields = ["displayName", "name"];
navigator.contacts.find(fields, onSuccess, onError, options);
}
I also included the Cordova.js file in my btw. I'm at a complete loss here, and all I can find about this particular problem are more people asking this question, without an answer that works for me :(
It seems I'm supposed to answer my own question instead of putting the answer in the edit.
Okay, so I figured it out by trial and error. Apparently sometimes Cordova doesn't update the Cordova_plugins.js file after adding plugins with the CLI. So you need to run the 'build' command from the project folder in CLI.
So when you get the Uncaught ReferenceError warning, just check your cordova_plugins.js. If it's not updated do it manually!
Hope I can help someone with the same issues by providing this solution, however 'green' it might be.

GWAN is modifying jquery.min.js to error

I am doing an experimental HTML template wich comes with jquery.min.js file - one of the most popular javascript libraries.
When I load the template from my local hard drive it works fine.
When I upload it and load it from server (GWAN) I get error (I think is not the only one) in Chrome looks like this:
Uncaught SyntaxError: Unexpected token { jquery.min.js:3
I inspected a bit and realized there is a
function $
which was turned into
function$
by GWan. The space removed is causing an error in Chrome, Firefox and Safari. I haven't tested other browsers but my IDE also reports a syntax error in the downloaded from GWAN version of the JS file.
I have also tried uploading the files to another server (Apache) and no problem there. The js file was not modified...
Any clues on how to get over this? I suppose there is a bug in javascript on-the-fly optimization of GWan?
Thanks.
It's a known issue and it will be fixed in next release (soon)
You'll be able to disable minifying directly from a init.c script in G-WAN v4.10+, this way:
u8 *www_mini = (u8*)get_env(argv, USE_MINIFYING);
if(www_mini)
{
*www_mini = 0;
puts("> disable minifying");
}
You just have to wait for few days for the new v5 release.

Javascript plug-in doesnt appear on drupal

i want to put a soundcloud music player (http://stratus.sc/) on my drupalgardens page. i added an external source javascript library and uploaded a js file on the system as it says on the pluging website. all this tru the administration website of drupalgardens. When i check the sourcecode of my webpage it appears like the pluging is on the header. But it doesnt work, i cant see it. i activated all the jquery functions.
bit of sourcecode on header where the pluging seems there:
<script type="text/javascript" src="http://stratus.sc/stratus.js"></script>
<script type="text/javascript" src="http://NAMEOFMYSITE/sites/NAMEOFMYSITE/files/js/js_PRNQJr2GPf-FrbaSuV5IDQ1l6Lfby6e79KpPOUTf5kI.js"></script>
link:
http://bit.ly/10nyAHV
Any suggestions?
Note : The player im talking about is NOT the one that can be seen under the rotating banner. the one im talking about its supposed to be globally on the webpage at its seem on the pluging oficcial webpage
For one you're getting this console error: "Uncaught SyntaxError: Unexpected token < "
Not sure how that script is getting added but just removing the script tags may clear it up.
Even if the frame errors mentioned by KG are unrelated, you have to go clean that all up.
Your script should also be loaded after jquery. Since it looks like you have js aggregation turned on, I don't really know how to determine if drupal is loading things correctly. You can just tell your script to load in the footer instead of header if you're unsure. The links below explain how to do that.
Here are some javascript related resources for Drupal. They sometimes expect things to be handled differently.
The plugin is dependent on jQuery. By default, Drupal 7 loads jQuery 1.4. You may need to use the jQuery Update plugin to use 1.5, 1.7 or 1.8
Drupal Community docs about javascript:
http://drupal.org/node/756722
Drupal javascript API:
http://drupal.org/node/751744
I had a similar issue. Some reasons for a not working player are:
For some reason $ is not known (although jQuery is included). I replaced '$' by 'jQuery' and everything worked fine. That means use jquery(document).ready(... instead of $(document).ready(... and jQuery.stratus({.. instead of $.stratus({...
There is a typo on the stratos.sc web site. It should read $.stratus not $stratus (or jQuery.stratus, see previous hint).
Check that the source stratus.js and the initialisation code is included.
Mixture of https and http might be a good guess as reason for problems, but actually it works (I just tried it). If you can't find the problem, try to use a JavaScript debugger and check the error logs first!

Categories