Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed iOS bugs #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This is a Cordova/Ionic plugin for OCR process using Tesseract library for both Android and iOS. [Tesseract](https://github.com/tesseract-ocr/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.

```bash
TesseractPlugin.recognizeText(imageData, language, function(recognizedText) {
deferred.resolve(recognizedText);
Expand All @@ -14,6 +15,7 @@ This plugin defines a global `TesseractPlugin` object, which provides an API for
## Installation

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

```bash
$ ionic platform add android
```
Expand All @@ -23,7 +25,8 @@ $ ionic platform add android

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

#### Ionic
#### Ionic

```bash
$ git clone https://github.com/gustavomazzoni/cordova-plugin-tesseract
$ cp -rf cordova-plugin-tesseract your-project/cordova-plugin-tesseract
Expand All @@ -37,10 +40,10 @@ $ ionic plugin add cordova-plugin-tesseract
$ 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:

```bash
$ ionic build android
```
Expand All @@ -63,23 +66,31 @@ end
```

#### 3.2 Still at your ios platform folder, install the dependencies ([install the CocoaPods](https://cocoapods.org/) in case you don't have it yet) using the following commands:

```bash
$ pod install
```

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

```bash
$ ionic build ios
```

Your project is ready to use this plugin.

> Another option is use the plugin [cordova-plugin-cocoapods-support](https://github.com/blakgeek/cordova-plugin-cocoapods-support)

## 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

#### 1.1 Android

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](https://github.com/tesseract-ocr/tessdata/tree/3.04.00).
Expand All @@ -92,8 +103,14 @@ TesseractPlugin.loadLanguage(language, function(response) {
});
```

#### 1.2 iOS

You have to download file from [this link](https://github.com/tesseract-ocr/tessdata/tree/3.04.00) an copy in folder: `platforms/ios/YourProjectName/Resources/tessdata`

### 2. Get image data from your photo

Load the image you want the text to be recognized from. On your angular Controller use [`$cordovaCamera`](http://ngcordova.com/docs/plugins/camera/) or [`cordova-plugin-camera`](https://github.com/apache/cordova-plugin-camera) plugin to take the photo or load an image:

```bash
$cordovaCamera.getPicture(options).then(function(imageData) {
$scope.image = "data:image/jpeg;base64," + imageData;
Expand All @@ -102,7 +119,6 @@ $cordovaCamera.getPicture(options).then(function(imageData) {
$timeout(function() {
// DOM has finished rendering
// insert here the call to TesseractPlugin.recognizeText function to recognize the text

});
}, function(err) {
// error
Expand All @@ -111,7 +127,9 @@ $cordovaCamera.getPicture(options).then(function(imageData) {
```

### 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.

```bash
TesseractPlugin.recognizeText(imageData, language, function(recognizedText) {
$scope.text = recognizedText;
Expand Down
5 changes: 2 additions & 3 deletions src/ios/TesseractPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ - (void)ocrProcessingFinished:(NSString *)result

{
// Call the Failure Javascript function

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


} else
Expand All @@ -81,7 +80,7 @@ - (void)ocrProcessingFinished:(NSString *)result

// Call the Success Javascript function

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


}
Expand Down