Code Monkey home page Code Monkey logo

cordova-plugin-tesseract's Introduction

Cordova Tesseract-OCR Plugin - For Android and iOS

This is a Cordova/Ionic plugin for OCR process using Tesseract library for both Android and iOS. Tesseract is an Open Source library for OCR (Optical Character Recognition) process.

This plugin defines a global TesseractPlugin object, which provides an API for recognizing text on images.

  TesseractPlugin.recognizeText(imageData, language, function(recognizedText) {
    deferred.resolve(recognizedText);
  }, function(reason) {
    deferred.reject('Error on recognizing text from image. ' + reason);
  });

Installation

Before installing this plugin, make sure you have added the platform for your app:

$ ionic platform add android

-> substitute android with ios to build for iOS.

-> substitute ionic with cordova to build on cordova.

1. Download or clone this project, copy it to your app root folder and run ionic command to add the plugin:

Ionic

$ git clone https://github.com/gustavomazzoni/cordova-plugin-tesseract
$ cp -rf cordova-plugin-tesseract your-project/cordova-plugin-tesseract
$ cd your-project/
$ ionic plugin add cordova-plugin-tesseract

Cordova

$ cordova plugin add https://github.com/gustavomazzoni/cordova-plugin-tesseract

2. For Android platform:

2.5 Your project is ready to use this plugin on Android platform. Build your project:

$ ionic build android

3. For iOS platform:

3.1 Inside root directory of your ios platform, create Podfile and add Tesseract OCR iOS (Tesseract library for iOS7+) as a dependency:

  • Create your-project/platforms/ios/Podfile
  • Add 'TesseractOCRiOS' dependency (replace 'ocr-translation' with the name of your project):
source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'ocr-translation.xcodeproj/'

target 'ocr-translation' do

	pod 'TesseractOCRiOS', '4.0.0'

end

3.2 Still at your ios platform folder, install the dependencies (install the CocoaPods in case you don't have it yet) using the following commands:

$ pod install

3.3 Your project is ready to use this plugin on iOS platform. Build your project:

$ ionic build ios

Your project is ready to use this plugin.

Usage

cordova-plugin-tesseract is designed to recognize text in images in many languages, but for that to work we need to have the tessdata of the language you want the text to be recognized.

To use this plugin and recognize text in images, you need to:

1. Download the language

As soon as you enter on your OCR use case, call TesseractPlugin.loadLanguage function to download the tessdata for your language.

Language must be in format like eng . For a list of compatible languages check this link.

TesseractPlugin.loadLanguage(language, function(response) {
  deferred.resolve(response);
}, function(reason) {
  deferred.reject('Error on loading OCR file for your language. ' + reason);
});

2. Get image data from your photo

Load the image you want the text to be recognized from. On your angular Controller use $cordovaCamera or cordova-plugin-camera plugin to take the photo or load an image:

$cordovaCamera.getPicture(options).then(function(imageData) {
  $scope.image = "data:image/jpeg;base64," + imageData;
  $scope.text = null;

  $timeout(function() {
    // DOM has finished rendering
    // insert here the call to TesseractPlugin.recognizeText function to recognize the text
    
  });
}, function(err) {
  // error
  console.log('ERROR with camera plugin. Error: ' + err);
});

3. Recognize text from image

Then, after loaded the image, just call TesseractPlugin.recognizeText function with the image data, the language of the text in the image and a callback function to be called after the operation is done.

TesseractPlugin.recognizeText(imageData, language, function(recognizedText) {
  $scope.text = recognizedText;
}, function(reason) {
  console.log('Error on recognizing text from image. ' + reason);
});

cordova-plugin-tesseract's People

Contributors

gustavomazzoni avatar kartagis avatar varun-garg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-tesseract's Issues

overwritten files

Hi, it seems that the installation procedure require modifying generated code, which will presumably be overwritten on the next install. Is there any way to get this working without the need to modify generated code?

Plugin with id 'com.github.dcendents.android-maven' not found.

Plugin with id 'com.github.dcendents.android-maven' not found.

~/platforms/android/tess-two/build.gradle:
import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

Getting Error

Project with path ':tess-two' could not be found in root project 'android'.

Installation issue

I can't install plugin

having this error

Could not install from "git+https:\github.com\gustavomazzoni\cordova-plugin-tesseract.git#e909e00977161e53d905ffaf78dd5b92e497dcee" as it does not contain a package.json file.

Android run time error

Hi,

If i try to run app on android device i am getting below error.

Error:Execution failed for task ':transformClassesWithJarMergingForDebug'.

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/googlecode/leptonica/android/AdaptiveMap.class
if i removed this plugin everything start working.
Can you suggest some solution to resolve this issue please ?

Thanks,
Jitendra

Throwing errors when calling TesseractPlugin.loadLanguage

Here's what I've got

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';

/**
 * Generated class for the MainPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */

@Component({
  selector: 'page-main',
  templateUrl: 'main.html',
})
export class MainPage {

  constructor(public navCtrl: NavController, public navParams: NavParams) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad MainPage');
  }

    TesseractPlugin.loadLanguage(language, function(response) {
  deferred.resolve(response);
}, function(reason) {
  deferred.reject('Error on loading OCR file for your language. ' + reason);
});
}

Error Produced:

[22:30:38]  typescript: src/pages/main/main.ts, line: 24
            ';' expected.

      L24:      TesseractPlugin.loadLanguage(language, function(response) {
      L25:    deferred.resolve(response);

[22:30:38]  typescript: src/pages/main/main.ts, line: 24
            Parameter declaration expected.

      L24:      TesseractPlugin.loadLanguage(language, function(response) {
      L25:    deferred.resolve(response);

[22:30:38]  typescript: src/pages/main/main.ts, line: 26
            Unexpected token. A constructor, method, accessor, or property was expected.

      L25:    deferred.resolve(response);
      L26:  }, function(reason) {
      L27:    deferred.reject('Error on loading OCR file for your language. ' + reason);

[22:30:38]  typescript: src/pages/main/main.ts, line: 28
            Unexpected token. A constructor, method, accessor, or property was expected.

      L27:    deferred.reject('Error on loading OCR file for your language. ' + reason);
      L28:  });

[22:30:38]  typescript: src/pages/main/main.ts, line: 24
            Duplicate function implementation.

      L24:      TesseractPlugin.loadLanguage(language, function(response) {
      L25:    deferred.resolve(response);

[22:30:38]  typescript: src/pages/main/main.ts, line: 25
            Cannot find name 'deferred'.

      L24:      TesseractPlugin.loadLanguage(language, function(response) {
      L25:    deferred.resolve(response);
      L26:  }, function(reason) {

[22:30:38]  typescript: src/pages/main/main.ts, line: 26
            Duplicate function implementation.

      L25:    deferred.resolve(response);
      L26:  }, function(reason) {
      L27:    deferred.reject('Error on loading OCR file for your language. ' + reason);

[22:30:38]  typescript: src/pages/main/main.ts, line: 27
            Cannot find name 'deferred'.

      L26:  }, function(reason) {
      L27:    deferred.reject('Error on loading OCR file for your language. ' + reason);
      L28:  });

[22:30:38]  build finished in 9.67 s

[22:30:38]  build started ...
[22:30:38]  transpile update started ...
[22:30:38]  transpile update finished in 83 ms
[22:30:38]  deeplinks update started ...
[22:30:38]  deeplinks update finished in 56 ms
[22:30:38]  webpack update started ...
[22:30:40]  webpack update finished in 1.32 s
[22:30:44]  typescript: src/pages/main/main.ts, line: 24
            ';' expected.

      L24:      TesseractPlugin.loadLanguage(language, function(response) {
      L25:    deferred.resolve(response);

[22:30:44]  typescript: src/pages/main/main.ts, line: 24
            Parameter declaration expected.

      L24:      TesseractPlugin.loadLanguage(language, function(response) {
      L25:    deferred.resolve(response);

[22:30:44]  typescript: src/pages/main/main.ts, line: 26
            Unexpected token. A constructor, method, accessor, or property was expected.

      L25:    deferred.resolve(response);
      L26:  }, function(reason) {
      L27:    deferred.reject('Error on loading OCR file for your language. ' + reason);

[22:30:44]  typescript: src/pages/main/main.ts, line: 28
            Unexpected token. A constructor, method, accessor, or property was expected.

      L27:    deferred.reject('Error on loading OCR file for your language. ' + reason);
      L28:  });

[22:30:44]  typescript: src/pages/main/main.ts, line: 24
            Duplicate function implementation.

      L24:      TesseractPlugin.loadLanguage(language, function(response) {
      L25:    deferred.resolve(response);

[22:30:44]  typescript: src/pages/main/main.ts, line: 25
            Cannot find name 'deferred'.

      L24:      TesseractPlugin.loadLanguage(language, function(response) {
      L25:    deferred.resolve(response);
      L26:  }, function(reason) {

[22:30:44]  typescript: src/pages/main/main.ts, line: 26
            Duplicate function implementation.

      L25:    deferred.resolve(response);
      L26:  }, function(reason) {
      L27:    deferred.reject('Error on loading OCR file for your language. ' + reason);

[22:30:44]  typescript: src/pages/main/main.ts, line: 27
            Cannot find name 'deferred'.

      L26:  }, function(reason) {
      L27:    deferred.reject('Error on loading OCR file for your language. ' + reason);
      L28:  });

Add Language

Can I Add Language "Equ". IS there Support ?
Thanks

Cannot find Symbol

Hi ! Thank for your work.

I have just one problem with ionic 3. When I use ionic cordova build android, I have one error : Cannot find symbol. Like @SiZe. How can I fix that ?

Thanks !

Character set

Is it possible to limit the characters that Tesseract attempts to recognise?

Load Language Error

TesseractPlugin.loadLanguage resolves, but with this error:

Error: Creation of directory /storage/emulated/0/OCRFolder/ on sdcard failed

I have the rule in my AndroidManifest.xml:

But the app does not prompt for permissions to write to external storage.

Support Image Path Parameter

Instead of passing base64 encoded image data, please help add support for passing image path since the image size may be big

Can't compile the project in any other cloud compilers other than ionic

Hi,

There has been some problem compiling with ionic cli (for other plugins). so I am compiling in a cloud compiler which works perfectly for other plugins.but this plugin showing an error.

I suspect that because claseAuxiliar.h has a TesseractOCR/TesseractOCR.h .I think you already mentioned to include the tesseract library. But,the problem is I can't add files,because I am using a cloud compiler.

So,could you please add tesseract library in this project (if possible). Atleast for ios. I think adding tesseract library in src/ios is enough (sorry if I am wrong).

Failed to read bitmap

When calling TesseractPlugin.recognizeText I get this error: "Failed to read bitmap."
any clue what's the problem here?

log:

I/Tesseract(native)(30577): Initialized Tesseract API with language=eng
E/ReadFile(30577): Bitmap must be non-null
V/TesseractPlugin(30577): Exception in Execute:Failed to read bitmap

The problem is that the created bitmap is null and I don't know why.
Using Ionic2 with Angular2 and have the exact code as written in the readMe
Thanks for any help!!

TesseractPlugin is not defined

I don't know if is an issue or if I'm doing something wrong, but I'm getting "TesseractPlugin is not defined" when I try to call TesseractPlugin.loadLanguage or TesseractPlugin.recognizeText.

The project is building with success, but I'm having this problem, could someone help me?

Data file not found

Hello @gustavomazzoni
there is an error on my application, the error like this, I try to figure it out, but I surrender, I have no idea what should I do, please help me

D/SystemWebChromeClient: file:///android_asset/www/js/percobaan.js: Line 28 : Error on recognizing text from image. Data file not found at /storage/emulated/0/OCRFolder/tessdata/en.traineddata
I/chromium: [INFO:CONSOLE(28)] "Error on recognizing text from image. Data file not found at /storage/emulated/0/OCRFolder/tessdata/en.traineddata", source: file:///android_asset/www/js/percobaan.js (28)
D/CordovaActivity: Paused the activity.
D/CordovaActivity: Stopped the activity.
E/chromium: [ERROR:gl_context_virtual.cc(39)] Trying to make virtual context current without decoder.

here's my code

function cameraTakePicture() { 
   navigator.camera.getPicture(onSuccess, onFail, {  
      quality: 50, 
      destinationType: Camera.DestinationType.DATA_URL
   });  
   
   function onSuccess(imageData) { 
   	
		imageData = "data:image/jpeg;base64," + imageData;

		TesseractPlugin.recognizeText(imageData, 'en', function(recognizedText) {
		  $scope.text = recognizedText;
		  console.log(recognizedText);
		}, function(reason) {
		  console.log('Error on recognizing text from image. ' + reason);
		});
   }  
   
   function onFail(message) { 
      alert('Failed because: ' + message); 
   } 
}

Installation Instructions Correction

1. The following line is wrong:
compile project(':tess-two')
It should be:
compile 'com.rmtheis:tess-two:8.0.0'

2. I think the following line should be removed:
2.4 Edit your-project/platforms/android/cordova/lib/build.js file that generates settings.gradle file:

Downloading more than one language

I have a use case where I need to download more than one language.
When calling the loadLanguage function twice the one after the other, a weird bug comes in:
The first language downloaded is saved as the second language - and only one traineddata file is saved.
I think the issue is related to the global lang variable and due to the download executing in the background.
In my view the expected behavior is having the success callback (of loadLanguage) invoke only when the download is completed, so I could wait for that before calling the loadLanguage again with the second language.

I'd like to hear your opinion and let me know if you attending to fix it...

iOS build problem

Hey!
Trying to use your plugin in ionic 2 on iOS but after installing pod I encountered problem:

diff: /Podfile.lock: No such file or directory
diff: /Manifest.lock: No such file or directory
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

I tried everything like reinstalling pod, updating cocapods etc. But the problem persists.

I found out that there is a script in Xcode project Build Phases named [CP] Check Pods Manifest.lock with contents:

diff "${PODS_PODFILE_DIR_PATH}/Podfile.lock" "${PODS_ROOT}/Manifest.lock" > /dev/null
if [ $? != 0 ] ; then
   echo "error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation." > &2
   exit 1
fi

There is clearly some problem with PODS_PODFILE_DIR_PATH and PODS_ROOT because files Podfile.lock and Manifest.lock exists in locations: platforms/ios/Podfile.lock, platforms/ios/Pods/Manifest.lock.

After manually editing script to point to correct paths and running ionic build ios there is another error:

/platforms/ios/DemoApp/Plugins/cordova-plugin-tesseract/claseAuxilar.h:12:9: fatal error: 'TesseractOCR/TesseractOCR.h' file not found

As I found there is Pod named TesseractOCRiOS installed instead of TessaractOCR. When I edited claseAuxilar.h file using TesseractOCRiOS/TesseractOCR.h,error still persisted in CLI, but xCode build managed to get over it and then prompted error in TesseractPlugin.m file.

No visible @interface for 'CDVPluginResult' declares the selector 'toErrorCallbackString:'

in lines 75 and 84 of TesseractPlugin.m.
After fixing this problem with my own cordova plugin result handling, there is Linker Error:

Library not found for -lTesseractOCRiOS

Is there any option to easily build and run ionic project with this plugin? Is there any chance to not use cocoa pods? How can I actually get this plugin to work on ios?

Thanks in advance

Execution failed for task ':tess-two:compileReleaseJavaWithJavac'.

Hey Please help me out I am getting the following error. I have follow all the steps what was have given.

Error :

symbol: class IntRange
location: class JpegIO
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Pixa.java:359: error: cannot find symbol
public boolean getBoxGeometry(int index, @SiZe(min=4) int[] dimensions) {
^
symbol: class Size
location: class Pixa
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Rotate.java:106: error: cannot find symbol
public static Pix rotateOrth(Pix pixs, @IntRange(from=0, to=3) int quads) {
^
symbol: class IntRange
location: class Rotate
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:508: error: cannot find symbol
@workerthread
^
symbol: class WorkerThread
location: class TessBaseAPI
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:533: error: cannot find symbol

@WorkerThread
 ^

symbol: class WorkerThread
location: class TessBaseAPI
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:556: error: cannot find symbol
@workerthread
^
symbol: class WorkerThread
location: class TessBaseAPI
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:577: error: cannot find symbol
@workerthread
^
symbol: class WorkerThread
location: class TessBaseAPI
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:593: error: cannot find symbol
@workerthread
^
symbol: class WorkerThread
location: class TessBaseAPI
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:753: error: cannot find symbol

@WorkerThread

 ^

symbol: class WorkerThread
location: class TessBaseAPI
36 errors
:tess-two:compileReleaseJavaWithJavac FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':tess-two:compileReleaseJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug
    option to get more log output.

BUILD FAILED

Total time: 2 mins 27.049 secs
Error: cmd: Command failed with exit code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Pix.java:20: error: package android.support.annotation does not exist
import android.support.annotation.ColorInt;
^
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Pix.java:21: error: package android.support.annotation does not exist
import android.support.annotation.Size;
^
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Binarize.java:19: error: package android.support.annotation does not exist

import android.support.annotation.FloatRange;
^
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Box.java:20: error: package android.support.annotation does not exist
import android.support.annotation.Size;
^
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Boxa.java:20: error: package android.support.annotation does not exist
import android.support.annotation.Size;
^
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Constants.java:19: error: package android.support.annotation does not exis
t
import android.support.annotation.IntDef;
^
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Constants.java:56: error: cannot find symbol
@IntDef({L_INSERT, L_COPY, L_CLONE})
^
symbol: class IntDef
location: class Constants
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Constants.java:79: error: cannot find symbol
@IntDef({L_SORT_INCREASING, L_SORT_DECREASING})
^
symbol: class IntDef
location: class Constants
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Constants.java:89: error: cannot find symbol
@IntDef({L_SORT_BY_X, L_SORT_BY_Y, L_SORT_BY_WIDTH, L_SORT_BY_HEIGHT, L_SORT
_BY_MIN_DIMENSION,
^
symbol: class IntDef
location: class Constants
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Edge.java:19: error: package android.support.annotation does not exist
import android.support.annotation.IntDef;
^
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Edge.java:38: error: cannot find symbol
@IntDef({L_HORIZONTAL_EDGES, L_VERTICAL_EDGES, L_ALL_EDGES})
^
symbol: class IntDef
location: class Edge
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\JpegIO.java:21: error: package android.support.annotation does not exist
import android.support.annotation.IntRange;
^
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\MorphApp.java:19: error: package android.support.annotation does not exist

import android.support.annotation.IntDef;
^
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\MorphApp.java:38: error: cannot find symbol
@IntDef({L_TOPHAT_BLACK, L_TOPHAT_WHITE})
^
symbol: class IntDef
location: class MorphApp
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Pixa.java:20: error: package android.support.annotation does not exist
import android.support.annotation.Size;
^
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Rotate.java:19: error: package android.support.annotation does not exist
import android.support.annotation.IntRange;
^
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:22: error: package android.support.annotation does not ex
ist
import android.support.annotation.IntDef;
^
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:23: error: package android.support.annotation does not ex
ist
import android.support.annotation.WorkerThread;
^
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:60: error: cannot find symbol
@IntDef({PSM_OSD_ONLY, PSM_AUTO_OSD, PSM_AUTO_ONLY, PSM_AUTO, PSM_SINGLE
_COLUMN,
^
symbol: class IntDef
location: class PageSegMode
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:124: error: cannot find symbol
@IntDef({OEM_TESSERACT_ONLY, OEM_CUBE_ONLY, OEM_TESSERACT_CUBE_COMBINED, OEM
_DEFAULT})
^
symbol: class IntDef
location: class TessBaseAPI
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:151: error: cannot find symbol
@IntDef({RIL_BLOCK, RIL_PARA, RIL_TEXTLINE, RIL_WORD, RIL_SYMBOL})
^
symbol: class IntDef
location: class PageIteratorLevel
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Pix.java:130: error: cannot find symbol
public boolean getDimensions(@SiZe(min=3) int[] dimensions) {
^
symbol: class Size
location: class Pix
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Pix.java:302: error: cannot find symbol
public void setPixel(int x, int y, @ColorInt int color) {
^
symbol: class ColorInt
location: class Pix
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Binarize.java:124: error: cannot find symbol
@FloatRange(from=0.0, to=1.0) float
scoreFraction) {
^
symbol: class FloatRange
location: class Binarize
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Binarize.java:190: error: cannot find symbol
public static Pix sauvolaBinarizeTiled(Pix pixs, int whsize, @FloatRange(fro
m=0.0) float factor,
^
symbol: class FloatRange
location: class Binarize
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Box.java:190: error: cannot find symbol
public boolean getGeometry(@SiZe(min=4) int[] geometry) {
^
symbol: class Size
location: class Box
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Boxa.java:121: error: cannot find symbol
public boolean getGeometry(int index, @SiZe(min=4) int[] geometry) {
^
symbol: class Size
location: class Boxa
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\JpegIO.java:64: error: cannot find symbol
public static byte[] compressToJpeg(Pix pixs, @IntRange(from=0, to=100) int
quality,
^
symbol: class IntRange
location: class JpegIO
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Pixa.java:359: error: cannot find symbol
public boolean getBoxGeometry(int index, @SiZe(min=4) int[] dimensions) {
^
symbol: class Size
location: class Pixa
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\leptonica\an
droid\Rotate.java:106: error: cannot find symbol
public static Pix rotateOrth(Pix pixs, @IntRange(from=0, to=3) int quads) {
^
symbol: class IntRange
location: class Rotate
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:508: error: cannot find symbol
@workerthread
^
symbol: class WorkerThread
location: class TessBaseAPI
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:533: error: cannot find symbol
@workerthread
^
symbol: class WorkerThread
location: class TessBaseAPI
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:556: error: cannot find symbol
@workerthread
^
symbol: class WorkerThread
location: class TessBaseAPI
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:577: error: cannot find symbol
@workerthread
^
symbol: class WorkerThread
location: class TessBaseAPI
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:593: error: cannot find symbol
@workerthread
^
symbol: class WorkerThread
location: class TessBaseAPI
C:\Users\HP\tesseract\platforms\android\tess-two\src\com\googlecode\tesseract\an
droid\TessBaseAPI.java:753: error: cannot find symbol
@workerthread
^
symbol: class WorkerThread
location: class TessBaseAPI
36 errors

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':tess-two:compileReleaseJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug
    option to get more log output.

[ERROR] An error occurred while running cordova build android (exit code 1).

Fix Deprecated methods toSuccessCallbackString

When i try to build IOS into Xcode i have 2 deprecated red errors directly in the plugin code about the callback method.

[self writeJavascript: [pluginResult toSuccessCallbackString:callbackId]];

I replace the errors lines by this line below as recommanded at (http://stackoverflow.com/questions/28850016/how-do-i-replace-the-deprecated-methods-tosuccesscallbackstring-and-writejavascr)

[self.commandDelegate sendPluginResult:pluginResult callbackId:callbackID];

Now it work :)

(node:18840) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: Command failed with exit code 1 Error output:

When tried to use tesseractPlugin, getting below error while running the project. even I am not able to build the project using - ionic cordova build android

Build file '...\platforms\android\build.gradle' line: 33

(node:18840) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred evaluating root project 'android'.

Could not find method compile() for arguments [com.rmtheis:tess-two:6.1.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Steps followed:-
Download or clone the cordova-plugin-tesseract and install it
$ git clone https://github.com/gustavomazzoni/cordova-plugin-tesseract
$ ionic plugin add path-to-your/cordova-plugin-tesseract

Refresh platform folders
$ ionic platform rm android
$ ionic platform add android

// Follow all gustavomazzoni steps, but 2.3
2.3 Edit your-project/platforms/android/build.gradle file and add 'tess-two' like this

Original Recommantion at original tess-two github (https://github.com/rmtheis/tess-two) is

dependencies {
// SUB-PROJECT DEPENDENCIES END
//compile 'com.rmtheis:tess-two:8.0.0' // tried with this also
compile 'com.rmtheis:tess-two:6.1.1'
}

Update use plugin

Hello, I want to use this plugin but with this documentation it isn't work. Can you update it? Thanks.

Update 2.4 in README.md

Hello,
2.4 says to include tess-two in project-root/platforms/android/cordova/lib/build.js, but there are no such lines in it. It seems to be project-root/platforms/android/cordova/lib/builders/GradleBuilder.js, and projectPath seems to be this.root. I can provide a PR if you want.

ReferenceError: deferred is not defined [ionic3]

Dear gustavomazzoni,

i have defined these variable at the top of file

declare var TesseractPlugin: any;
var language = 'eng';

i get deferred not defined.
when i declare this too at the top of file still i am getting deferred is not defined.
declare var deferred: any;

 onCamera() {
    TesseractPlugin.loadLanguage(language, function(response) {
      deferred.resolve(response);
    }, function(reason) {
      deferred.reject('Error on loading OCR file for your language. ' + reason);
    });

    const options: CameraOptions = {
      quality: 100,
      destinationType: this.camera.DestinationType.FILE_URI,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE
    }

    this.camera.getPicture(options).then((imageData) => {
        console.log(imageData)
        TesseractPlugin.recognizeText(imageData, language, function(recognizedText) {
          deferred.resolve(recognizedText);
          console.log(deferred.resolve(recognizedText))
          console.log(recognizedText);
        }, function(reason) {
          deferred.reject('Error on recognizing text from image. ' + reason);
        });

    }, (err) => {
      console.log(err)
    });
   }

Runtime error : ... couldn't find "libjpgt.so"

Hello,
I'm trying to use the plugin on an Android (6.0.1) but when I call the recognizeText method I got this error :

06-29 22:08:45.412 31275 31408 W System.err: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/io.ionic.starter-1/base.apk"],nativeLibraryDirectories=[/data/app/io.ionic.starter-1/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libjpgt.so"
06-29 22:08:45.419 31275 31408 W System.err: 	at java.lang.Runtime.loadLibrary(Runtime.java:367)
06-29 22:08:45.419 31275 31408 W System.err: 	at java.lang.System.loadLibrary(System.java:1076)
06-29 22:08:45.419 31275 31408 W System.err: 	at com.googlecode.tesseract.android.TessBaseAPI.<clinit>(TessBaseAPI.java:44)
06-29 22:08:45.419 31275 31408 W System.err: 	at com.gmazzoni.cordova.TesseractPlugin.recognizeText(TesseractPlugin.java:80)
06-29 22:08:45.419 31275 31408 W System.err: 	at com.gmazzoni.cordova.TesseractPlugin.execute(TesseractPlugin.java:48)
06-29 22:08:45.419 31275 31408 W System.err: 	at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
06-29 22:08:45.419 31275 31408 W System.err: 	at org.apache.cordova.PluginManager.exec(PluginManager.java:132)
06-29 22:08:45.419 31275 31408 W System.err: 	at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:57)
06-29 22:08:45.419 31275 31408 W System.err: 	at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
06-29 22:08:45.419 31275 31408 W System.err: 	at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
06-29 22:08:45.419 31275 31408 W System.err: 	at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:41)
06-29 22:08:45.419 31275 31408 W System.err: 	at android.os.Handler.dispatchMessage(Handler.java:102)
06-29 22:08:45.420 31275 31408 W System.err: 	at android.os.Looper.loop(Looper.java:148)
06-29 22:08:45.420 31275 31408 W System.err: 	at android.os.HandlerThread.run(HandlerThread.java:61)

Any idea how embed this libjpgt lib ?

Thank you

Tesseract always saying image is "Bad Base-64"

Hi,
I have installed the plugin in an App for Android made with Ionic Framework.
I am trying to get an image with cordova-image-camera which is getting a base64 image, which is correct (if I use it in an it show the image correctly).
I pass that base64 as imageData input, but Tesseract always get an Exception "Bad Base-64".
Do you what could be the reason?

Example code:

try {
	TesseractPlugin.loadLanguage('ita', function(response) {
		debugLog('Loading OCR language successful');
	}, function(reason) {
		debugLog('Error on loading OCR file for your language. ' + reason);
	});

	var _testImage ="data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAANCAIAAAArLKlOAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABvSURBVChTpZBRFgARCEWty4JaT6tpMxbTiITDOI25X9S7QuArfmsJY1CAtCbUesSk+4JpBK1DYKIsI1IW37SOHD+llsJOqxPG0FmTfGF6WsY1rf7BqPq0JXbQcqsN+DSthBXL2HMVa+wu6eBKY34AAZZMtGg8cLgAAAAASUVORK5CYII=";
	TesseractPlugin.recognizeText(_testImage  , 'ita', function(recognizedText) {
		debugLog("Tesseract recognized text: " + recognizedText);
	}, function(error) {
		debugLog('Error recognizing text from image: ' + error);
	});
}
catch(e) {
	debugLog("Tesseract Error: " + objToString(e.message) );
}

The loadLanguage() call works successfully.
The recognizeText() always returns the function(reason), with the message: "Bad Base-64";

Thankyou.
Carlo

Download Language

What does "Download the language" means? Do you need internet connection in this sir? Do you have any working Ionic App sir using this plugin?

Java Error on calling recognizeText

Hi @gustavomazzoni
I just followed your instructions to install this plugin and I tried it with a short sample code:

TesseractPlugin.loadLanguage('eng', function(c) {
  console.log("loadLanguage ok");
  TesseractPlugin.recognizeText(imageData, 'eng', function(recognizedText) {
    console.log(recognizedText);
  }, function(reason) {
    console.log('Error on recognizing text from image. ' + reason);
  });
});

After running it on an Android device, the only message which appears in the browser console is loadLanguage ok

Then, I typed adb logcat:

V/TesseractPlugin(12960): Action: recognizeText
V/TesseractPlugin(12960): Starting process to recognize text in photo.
D/skia    (12960): --- SkImageDecoder::Factory returned null
V/TesseractPlugin(12960): Before baseApi
I/art     (12960): Rejecting re-init on previously-failed class java.lang.Class<com.googlecode.tesseract.android.TessBaseAPI>
W/System.err(12960): java.lang.UnsatisfiedLinkError: com.googlecode.tesseract.android.TessBaseAPI
W/System.err(12960):    at com.gmazzoni.cordova.TesseractPlugin.recognizeText(TesseractPlugin.java:80)
W/System.err(12960):    at com.gmazzoni.cordova.TesseractPlugin.execute(TesseractPlugin.java:48)
W/System.err(12960):    at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
W/System.err(12960):    at org.apache.cordova.PluginManager.exec(PluginManager.java:133)
W/System.err(12960):    at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
W/System.err(12960):    at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
W/System.err(12960):    at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err(12960):    at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:39)
W/System.err(12960):    at android.os.Handler.dispatchMessage(Handler.java)
W/System.err(12960):    at android.os.Looper.loop(Looper.java)
W/System.err(12960):    at android.os.HandlerThread.run(HandlerThread.java)

What is missing?

Unhandled Exec Call for TesseractPlugin.loadLanguage and TesseractPlugin.recognizeText

image

Platform: iOS
TesseractPlugin Version: 4.0.0
OS: Windows 7 Ultimate x64
Development framework: Cordova with Framework7
Description: Successfully pod installed the library and successfully built with Xcode
IDE: Visual Studio 2017
Simulate: Simulate with browser - iPad Pro with VS 2017
Expected result: No need manually handle the request of all TesseractPlugin functions

Build error TessBaseAPI

..platforms\android\src\com\tesseract\phonegap\TesseractPlugin.
java:17: error: cannot find symbol

import com.googlecode.tesseract.android.TessBaseAPI;
and

java:80: error: cannot find symbol
TessBaseAPI baseApi = new TessBaseAPI();

How to work with tesseract in my project?

Well you explained very well that how to integrate into our cordova project, but i'm a new user on ionic2 i don't have any idea how to initialize code to run that OCR scanner like in we do android application development.

Can you provide any example so that i can start, Thanks.

Language file is not available anymore (404)

https://cdn.rawgit.com/naptha/tessdata/gh-pages/3.02/english.traineddata.gz isn't there. I see this error in adb logs (Android) but i get 'OK' in my callback:

Starting process to load OCR language file.
01-18 00:42:33.646 30483 30542 V TesseractPlugin: Result: Ok
01-18 00:42:33.646 30483 31720 V TesseractPlugin: Downloading english.traineddata
01-18 00:42:33.776 30483 31720 E TesseractPlugin: Unable to copy english.traineddata java.io.FileNotFoundException: https://cdn.rawgit.com/naptha/tessdata/gh-pages/3.02/english.traineddata.gz
01-18 00:42:33.780 30483 30483 V TesseractPlugin: Download and copy done! Nothing else to do.
01-18 00:43:14.375 30483 30542 V TesseractPlugin:

Why do i get no error but it never even finds the file?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.