Skip to content

Commit a8b5d57

Browse files
committed
update to v2 (beta)
1 parent 9129d14 commit a8b5d57

File tree

12 files changed

+113
-30
lines changed

12 files changed

+113
-30
lines changed

packages/learning_text_recognition/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.0.4] - 23 November 2021
2+
3+
* Update to MLKit Text Recognition v2 (Beta) to support Chinese, Devanagari, Japanese and Korean scripts
4+
15
## [0.0.3] - 23 November 2021
26

37
* Update dependencies

packages/learning_text_recognition/README.md

+36-16
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,19 @@
22

33
The easy way to use ML Kit for text recognition in Flutter.
44

5-
ML Kit's text recognition can recognize text in any Latin-based character set. They can also be used to automate data-entry tasks such as processing credit cards, receipts, and business cards.
5+
ML Kit's text recognition can recognize text in Latin, Chinese, Devanagari, Japanese and Korean scripts and a [wide range of languages](https://developers.google.com/ml-kit/vision/text-recognition/v2/languages). They can also be used to automate data-entry tasks such as processing credit cards, receipts, and business cards.
66

77
<img src="https://github.com/salkuadrat/learning/raw/master/packages/learning_text_recognition/screenshot.jpg" alt="universe" width="280">
88

99
## Getting Started
1010

1111
Add dependency to your flutter project:
1212

13-
```
14-
$ flutter pub add learning_text_recognition
15-
```
16-
17-
or
18-
19-
```yaml
20-
dependencies:
21-
learning_text_recognition: ^0.0.2
13+
```bash
14+
$ pub add learning_text_recognition
2215
```
2316

24-
Then run `flutter pub get`.
25-
17+
<!--
2618
## Configuration
2719
2820
You can configure your app to automatically download the ML model to the device after your app is installed from the Play Store. To do so, add the following declaration to your app's AndroidManifest.xml file.
@@ -31,17 +23,18 @@ You can configure your app to automatically download the ML model to the device
3123
<application ...>
3224
...
3325
<meta-data
34-
android:name="com.google.mlkit.vision.DEPENDENCIES"
35-
android:value="ocr" />
36-
<!-- To use multiple models: android:value="ocr,model2,model3" -->
26+
android:name="com.google.mlkit.vision.DEPENDENCIES"
27+
android:value="ocr" />
3728
</application>
3829
```
3930
4031
If you do not enable install-time model downloads, the model will be downloaded the first time you run the text recognition process. Requests you make before the download has completed will produce no results.
4132
33+
-->
34+
4235
## Usage
4336

44-
```
37+
```dart
4538
import 'package:learning_text_recognition/learning_text_recognition.dart';
4639
```
4740

@@ -71,7 +64,34 @@ InputCameraView(
7164
After getting the `InputImage`, we can start doing text recognition by calling method `process` from an instance of `TextRecognition`.
7265

7366
```dart
67+
// When using for Latin script
7468
TextRecognition textRecognition = TextRecognition();
69+
// or like this:
70+
TextRecognition textRecognition = TextRecognition(
71+
options: TextRecognitionOptions.Default
72+
);
73+
74+
// When using for Chinese script
75+
TextRecognition textRecognition = TextRecognition(
76+
options: TextRecognitionOptions.Chinese
77+
);
78+
79+
// When using for Devanagari script
80+
TextRecognition textRecognition = TextRecognition(
81+
options: TextRecognitionOptions.Devanagari
82+
);
83+
84+
// When using for Japanese script
85+
TextRecognition textRecognition = TextRecognition(
86+
options: TextRecognitionOptions.Japanese
87+
);
88+
89+
// When using for Korean script
90+
TextRecognition textRecognition = TextRecognition(
91+
options: TextRecognitionOptions.Korean
92+
);
93+
94+
// Process text recognition...
7595
RecognizedText result = await textRecognition.process(image);
7696
```
7797

packages/learning_text_recognition/android/build.gradle

+15-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,19 @@ android {
3636

3737
dependencies {
3838
// MLKit Text Recognition
39-
implementation 'com.google.android.gms:play-services-mlkit-text-recognition:16.3.0'
39+
// implementation 'com.google.android.gms:play-services-mlkit-text-recognition:16.3.0'
40+
// To recognize Latin script
41+
implementation 'com.google.mlkit:text-recognition:16.0.0-beta1'
42+
43+
// To recognize Chinese script
44+
implementation 'com.google.mlkit:text-recognition-chinese:16.0.0-beta1'
45+
46+
// To recognize Devanagari script
47+
implementation 'com.google.mlkit:text-recognition-devanagari:16.0.0-beta1'
48+
49+
// To recognize Japanese script
50+
implementation 'com.google.mlkit:text-recognition-japanese:16.0.0-beta1'
51+
52+
// To recognize Korean script
53+
implementation 'com.google.mlkit:text-recognition-korean:16.0.0-beta1'
4054
}

packages/learning_text_recognition/android/src/main/java/com/salkuadrat/learning/learning_text_recognition/LearningTextRecognitionPlugin.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
5353

5454
private void process(MethodCall call, Result result) {
5555
InputImage image = getInputImage(call, result);
56+
String options = call.argument("options");
5657

5758
if (image != null) {
58-
textRecognition = new TextRecognition();
59+
textRecognition = new TextRecognition(options);
5960
textRecognition.process(image, result);
6061
}
6162
}

packages/learning_text_recognition/android/src/main/java/com/salkuadrat/learning/learning_text_recognition/TextRecognition.java

+18-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
import com.google.mlkit.vision.common.InputImage;
1111
import com.google.mlkit.vision.text.Text;
1212
import com.google.mlkit.vision.text.TextRecognizer;
13-
import com.google.mlkit.vision.text.TextRecognizerOptions;
13+
import com.google.mlkit.vision.text.latin.TextRecognizerOptions;
14+
import com.google.mlkit.vision.text.chinese.ChineseTextRecognizerOptions;
15+
import com.google.mlkit.vision.text.devanagari.DevanagariTextRecognizerOptions;
16+
import com.google.mlkit.vision.text.japanese.JapaneseTextRecognizerOptions;
17+
import com.google.mlkit.vision.text.korean.KoreanTextRecognizerOptions;
1418

1519
import java.util.ArrayList;
1620
import java.util.HashMap;
@@ -23,8 +27,18 @@ public class TextRecognition {
2327

2428
final TextRecognizer recognizer;
2529

26-
public TextRecognition() {
27-
this.recognizer = com.google.mlkit.vision.text.TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS);
30+
public TextRecognition(String options) {
31+
if (options == "chinese") {
32+
this.recognizer = com.google.mlkit.vision.text.TextRecognition.getClient(new ChineseTextRecognizerOptions.Builder().build());
33+
} else if (options == "devanagari") {
34+
this.recognizer = com.google.mlkit.vision.text.TextRecognition.getClient(new DevanagariTextRecognizerOptions.Builder().build());
35+
} else if (options == "japanese") {
36+
this.recognizer = com.google.mlkit.vision.text.TextRecognition.getClient(new JapaneseTextRecognizerOptions.Builder().build());
37+
} else if (options == "korean") {
38+
this.recognizer = com.google.mlkit.vision.text.TextRecognition.getClient(new KoreanTextRecognizerOptions.Builder().build());
39+
} else {
40+
this.recognizer = com.google.mlkit.vision.text.TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS);
41+
}
2842
}
2943

3044
public void process(@NonNull InputImage image, @NonNull final MethodChannel.Result result) {
@@ -109,9 +123,7 @@ List<Map<String, Object>> pointsToList(@NonNull Point[] points) {
109123
}
110124
return result;
111125
}
112-
113-
114-
126+
115127
public void dispose() {
116128
if (recognizer != null) {
117129
recognizer.close();

packages/learning_text_recognition/example/android/app/src/main/AndroidManifest.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@
4545
<meta-data
4646
android:name="flutterEmbedding"
4747
android:value="2" />
48-
<meta-data
48+
<!-- <meta-data
4949
android:name="com.google.mlkit.vision.DEPENDENCIES"
5050
android:value="ocr" />
51+
-->
5152
</application>
5253
</manifest>

packages/learning_text_recognition/example/lib/main.dart

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class TextRecognitionPage extends StatefulWidget {
3535
class _TextRecognitionPageState extends State<TextRecognitionPage> {
3636
TextRecognition? _textRecognition = TextRecognition();
3737

38+
/* TextRecognition? _textRecognition = TextRecognition(
39+
options: TextRecognitionOptions.Japanese
40+
); */
41+
3842
@override
3943
void dispose() {
4044
_textRecognition?.dispose();

packages/learning_text_recognition/example/pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ packages:
162162
path: ".."
163163
relative: true
164164
source: path
165-
version: "0.0.3"
165+
version: "0.0.4"
166166
matcher:
167167
dependency: transitive
168168
description:
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
library learning_text_recognition;
22

3+
export 'src/options.dart';
34
export 'src/text_recognition.dart';
45
export 'src/text.dart';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
enum TextRecognitionOptions {
2+
Default,
3+
Chinese,
4+
Devanagari,
5+
Japanese,
6+
Korean,
7+
}
8+
9+
String fromOptions(TextRecognitionOptions options) {
10+
switch (options) {
11+
case TextRecognitionOptions.Chinese:
12+
return 'chinese';
13+
case TextRecognitionOptions.Devanagari:
14+
return 'devanagari';
15+
case TextRecognitionOptions.Japanese:
16+
return 'japanese';
17+
case TextRecognitionOptions.Korean:
18+
return 'korean';
19+
default:
20+
return 'default';
21+
}
22+
}

packages/learning_text_recognition/lib/src/text_recognition.dart

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import 'package:flutter/services.dart';
22
import 'package:learning_input_image/learning_input_image.dart';
33

4+
import 'options.dart';
45
import 'text.dart';
56

67
class TextRecognition {
78
final MethodChannel channel = MethodChannel('LearningTextRecognition');
9+
final TextRecognitionOptions options;
810

9-
TextRecognition();
11+
TextRecognition({this.options = TextRecognitionOptions.Default});
1012

1113
Future<RecognizedText?> process(InputImage image) async {
1214
try {
13-
final result = await channel
14-
.invokeMethod('process', <String, dynamic>{'image': image.json});
15+
final result = await channel.invokeMethod('process', <String, dynamic>{
16+
'image': image.json,
17+
'options': fromOptions(options),
18+
});
1519

1620
if (result != null) {
1721
return RecognizedText.from(result);

packages/learning_text_recognition/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: learning_text_recognition
22
description: The easy way to use ML Kit for text recognition in Flutter.
3-
version: 0.0.3
3+
version: 0.0.4
44
# author: Salman S
55
homepage: https://github.com/salkuadrat/learning/tree/master/packages/learning_text_recognition
66
repository: https://github.com/salkuadrat/learning/tree/master/packages/learning_text_recognition

0 commit comments

Comments
 (0)