UNPKG

4.83 kBMarkdownView Raw
1# react-native-tesseract-ocr
2
3react-native-tesseract-ocr is a react-native wrapper for [Tesseract OCR](https://github.com/tesseract-ocr) using base on
4 - [tess-two](https://github.com/rmtheis/tess-two) for Android
5 - [Tesseract-OCR-iOS](https://github.com/gali8/Tesseract-OCR-iOS) for iOS *(Not implemented yet)*
6
7## Getting started
8
9`$ npm install react-native-tesseract-ocr --save`
10
11### Mostly automatic installation
12
13`$ react-native link react-native-tesseract-ocr`
14
15*Don't forget to ...*
16- *add [v3.04 trained data files](https://github.com/tesseract-ocr/tessdata/tree/3.04.00) to the appropriate folder*
17- *install [CocoaPods](https://cocoapods.org/) in your react-native project and add the following line to your Podfile then run `pod install` __(iOS only)__*
18 ```
19 pod 'TesseractOCRiOS', '4.0.0'
20 ```
21
22
23### Manual installation
24
25
26#### iOS
27
281. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
292. Go to `node_modules` ➜ `react-native-tesseract-ocr` and add `RNTesseractOcr.xcodeproj`
303. In XCode, in the project navigator, select your project. Add `libRNTesseractOcr.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
314. Run your project (`Cmd+R`)<
32
33#### Android
34
351. Open up `android/app/src/main/java/[...]/MainActivity.java`
36 - Add `import com.reactlibrary.RNTesseractOcrPackage;` to the imports at the top of the file
37 - Add `new RNTesseractOcrPackage()` to the list returned by the `getPackages()` method
382. Append the following lines to `android/settings.gradle`:
39 ```
40 include ':react-native-tesseract-ocr'
41 project(':react-native-tesseract-ocr').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-tesseract-ocr/android')
42 ```
433. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
44 ```
45 compile project(':react-native-tesseract-ocr')
46 ```
474. [v3.04 Trained data files](https://github.com/tesseract-ocr/tessdata/tree/3.04.00) for a language must be
48extracted in `android/app/src/main/assets/tessdata`.
49
50## Usage
51```javascript
52import RNTesseractOcr from 'react-native-tesseract-ocr';
53
54
55/**
56 * @param {string} imgPath - The path of the image.
57 * @param {string} lang - The language you want to process.
58 */
59RNTesseractOcr.startOcr(imgPath, lang)
60 .then((result) => {
61 this.setState({ ocrResult: result });
62 console.log("OCR Result: ", result);
63 })
64 .catch((err) => {
65 console.log("OCR Error: ", err);
66 })
67 .done();
68
69```
70
71### Supported languages
72 - LANG_AFRIKAANS
73 - LANG_AMHARIC
74 - LANG_ARABIC
75 - LANG_ASSAMESE
76 - LANG_AZERBAIJANI
77 - LANG_BELARUSIAN
78 - LANG_BOSNIAN
79 - LANG_BULGARIAN
80 - LANG_CHINESE_SIMPLIFIED
81 - LANG_CHINESE_TRADITIONAL
82 - LANG_CROATIAN
83 - LANG_DANISH
84 - LANG_ENGLISH
85 - LANG_ESTONIAN
86 - LANG_FRENCH
87 - LANG_GALICIAN
88 - LANG_GERMAN
89 - LANG_HEBREW
90 - LANG_HUNGARIAN
91 - LANG_ICELANDIC
92 - LANG_INDONESIAN
93 - LANG_IRISH
94 - LANG_ITALIAN
95 - LANG_JAPANESE
96 - LANG_KOREAN
97 - LANG_LATIN
98 - LANG_LITHUANIAN
99 - LANG_NEPALI
100 - LANG_NORWEGIAN
101 - LANG_PERSIAN
102 - LANG_POLISH
103 - LANG_PORTUGUESE
104 - LANG_RUSSIAN
105 - LANG_SERBIAN
106 - LANG_SLOVAK
107 - LANG_SPANISH
108 - LANG_SWEDISH
109 - LANG_TURKISH
110 - LANG_UKRAINIAN
111 - LANG_VIETNAMESE
112
113### If you want to use your own trained data file
114- Extract your own trained data file into `android/app/src/main/assets/tessdata` and rename it as `custom.traineddata`.
115
116
117## Example
118Try the included [TesseractOcrSample](https://github.com/jonathanpalma/react-native-tesseract-ocr/tree/master/tesseractOcrSample):
119- `git clone git@github.com:jonathanpalma/react-native-tesseract-ocr.git`
120- `cd react-native-tesseract-ocr/tesseractOcrSample/`
121- `npm install`
122
123*NOTE: Don't forget to ...*
124- *add [v3.04 trained data files](https://github.com/tesseract-ocr/tessdata/tree/3.04.00) to the appropriate folder*
125- *install [CocoaPods](https://cocoapods.org/) in your react-native project and add the following line to your Podfile then run `pod install` __(iOS only)__*
126 ```
127 pod 'TesseractOCRiOS', '4.0.0'
128 ```
129
130## TODOS
131- [ ] **Add iOS support**
132- [ ] Optimize ocr for large images
133
134## Contribution
135Contributions are welcome :raised_hands:
136
137## License
138This repository is distributed under [MIT license](https://github.com/jonathanpalma/react-native-tesseract-ocr/blob/master/LICENSE)
139 - [Tesseract OCR](https://github.com/tesseract-ocr) - maintained by Google, is distributed under [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0)
140 - [tess-two](https://github.com/rmtheis/tess-two) is distributed under [Apache 2.0 license](https://github.com/rmtheis/tess-two/blob/master/COPYING)
141 - [Tesseract-OCR-iOS](https://github.com/gali8/Tesseract-OCR-iOS) is distributed under [MIT license](https://github.com/gali8/Tesseract-OCR-iOS/blob/master/LICENSE.md)
142
143
\No newline at end of file