Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
84cc43c
WIP start of branch
bparrishMines Aug 20, 2018
5ea2157
Update dart code for TextRecognizer
bparrishMines Aug 21, 2018
3ceda90
Update tests
bparrishMines Aug 21, 2018
d2849f9
write better tests
bparrishMines Aug 21, 2018
9891e2c
Merge branch 'master' of github.com:flutter/plugins into mlkit_text_dart
bparrishMines Aug 21, 2018
9030142
update version logs
bparrishMines Aug 21, 2018
c1e3c5d
Merge branch 'master' of github.com:flutter/plugins into mlkit_text_dart
bparrishMines Sep 7, 2018
286b1cd
Update dart code for TextRecognizer
bparrishMines Sep 7, 2018
eddc986
Fix iOS TextRecognizer
bparrishMines Sep 7, 2018
36e4ffa
Small changes to cloud label detector comments
bparrishMines Sep 7, 2018
db66943
Model type for cloud detectors use string
bparrishMines Sep 7, 2018
94b4d00
Renamed file
bparrishMines Sep 7, 2018
84a848b
Correct version
bparrishMines Sep 7, 2018
3cb8da0
Formatting
bparrishMines Sep 7, 2018
b126b82
Filename change
bparrishMines Sep 7, 2018
ab866b9
README title name change
bparrishMines Sep 7, 2018
7149767
Merge branch 'master' of github.com:flutter/plugins into mlkit_text_dart
bparrishMines Sep 14, 2018
4f94667
Add detectInImage deprecation
bparrishMines Oct 5, 2018
098e69d
Take out name
bparrishMines Oct 5, 2018
58611f6
Update test to use processImage
bparrishMines Oct 5, 2018
e39222b
Merge branch 'master' of github.com:flutter/plugins into mlkit_text_dart
bparrishMines Oct 9, 2018
70f87eb
Merge branch 'mlkit_text_dart' of github.com:bparrishMines/plugins in…
bparrishMines Oct 9, 2018
8d42b73
Update iOS FaceDetector to lastest api
bparrishMines Oct 9, 2018
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
6 changes: 6 additions & 0 deletions packages/firebase_ml_vision/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.2.0

* **Breaking Change** Update TextDetector to TextRecognizer for android mlkit '17.0.0' and
firebase-ios-sdk '5.6.0'.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done in PRs: #733 and #732

* Added CloudLabelDetector.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done in: #695


## 0.1.2

* Fix example imports so that publishing will be warning-free.
Expand Down
23 changes: 13 additions & 10 deletions packages/firebase_ml_vision/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Google ML Kit for Firebase
# ML Kit for Firebase

[![pub package](https://img.shields.io/pub/v/firebase_ml_vision.svg)](https://pub.dartlang.org/packages/firebase_ml_vision)

A Flutter plugin to use the [Google ML Kit for Firebase API](https://firebase.google.com/docs/ml-kit/).
A Flutter plugin to use the [ML Kit for Firebase API](https://firebase.google.com/docs/ml-kit/).

For Flutter plugins for other Firebase products, see [FlutterFire.md](https://github.com/flutter/plugins/blob/master/FlutterFire.md).

Expand Down Expand Up @@ -42,12 +42,13 @@ Get an instance of a `FirebaseVisionDetector`.

```dart
final BarcodeDetector barcodeDetector = FirebaseVision.instance.barcodeDetector();
final CloudLabelDetector cloudLabelDetector = FirebaseVision.instance.cloudLabelDetector();
final FaceDetector faceDetector = FirebaseVision.instance.faceDetector();
final LabelDetector labelDetector = FirebaseVision.instance.labelDetector();
final TextDetector textDetector = FirebaseVision.instance.textDetector();
final TextRecognizer textRecognizer = FirebaseVision.instance.textRecognizer();
```

You can also configure all detectors except `TextDetector` with desired options.
You can also configure all detectors except `TextRecognizer` with desired options.

```dart
final LabelDetector detector = FirebaseVision.instance.labelDetector(
Expand All @@ -59,9 +60,10 @@ final LabelDetector detector = FirebaseVision.instance.labelDetector(

```dart
final List<Barcode> barcodes = await barcodeDetector.detectInImage(visionImage);
final List<Label> labels = await cloudLabelDetector.detectInImage(visionImage);
final List<Face> faces = await faceDetector.detectInImage(visionImage);
final List<Label> labels = await labelDetector.detectInImage(visionImage);
final List<TextBlock> blocks = await textDetector.detectInImage(visionImage);
final VisionText visionText = await textRecognizer.detectInImage(visionImage);
```

### 4. Extract data.
Expand Down Expand Up @@ -133,21 +135,22 @@ for (Label label in labels) {
d. Extract text.

```dart
for (TextBlock block in blocks) {
String text = visionText.text;
for (TextBlock block in visionText.blocks) {
final Rectangle<int> boundingBox = block.boundingBox;
final List<Point<int>> cornerPoints = block.cornerPoints;
final String text = block.text;
final List<RecognizedLanguage> languages = block.recognizedLanguages;

for (TextLine line in block.lines) {
// ...

// Same getters as TextBlock
for (TextElement element in line.elements) {
// ...
// Same getters as TextBlock
}
}
}
```

## Getting Started

See the `example` directory for a complete sample app using Google ML Kit for Firebase.
See the `example` directory for a complete sample app using ML Kit for Firebase.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,20 @@ public void onFailure(@NonNull Exception e) {

private FirebaseVisionCloudDetectorOptions parseOptions(Map<String, Object> optionsData) {
final int maxResults = (int) optionsData.get("maxResults");
final int modelType = (int) optionsData.get("modelType");
final String modelTypeStr = (String) optionsData.get("modelType");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a few changes with how to handle type so no changes to the API will break this.


final int modelType;
switch (modelTypeStr) {
case "stable":
modelType = FirebaseVisionCloudDetectorOptions.STABLE_MODEL;
break;
case "latest":
modelType = FirebaseVisionCloudDetectorOptions.LATEST_MODEL;
break;
default:
throw new IllegalArgumentException(String.format("No type for model: %s", modelTypeStr));
}

return new FirebaseVisionCloudDetectorOptions.Builder()
.setMaxResults(maxResults)
.setModelType(modelType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public void onMethodCall(MethodCall call, Result result) {
BarcodeDetector.instance.handleDetection(image, options, result);
} catch (IOException e) {
result.error("barcodeDetectorIOError", e.getLocalizedMessage(), null);
} catch (Exception e) {
result.error("barcodeDetectorError", e.getLocalizedMessage(), null);
}
break;
case "FaceDetector#detectInImage":
Expand All @@ -47,8 +45,6 @@ public void onMethodCall(MethodCall call, Result result) {
FaceDetector.instance.handleDetection(image, options, result);
} catch (IOException e) {
result.error("faceDetectorIOError", e.getLocalizedMessage(), null);
} catch (Exception e) {
result.error("faceDetectorError", e.getLocalizedMessage(), null);
}
break;
case "LabelDetector#detectInImage":
Expand All @@ -57,28 +53,22 @@ public void onMethodCall(MethodCall call, Result result) {
LabelDetector.instance.handleDetection(image, options, result);
} catch (IOException e) {
result.error("labelDetectorIOError", e.getLocalizedMessage(), null);
} catch (Exception e) {
result.error("labelDetectorError", e.getLocalizedMessage(), null);
}
break;
case "CloudLabelDetector#detectInImage":
try {
image = filePathToVisionImage((String) call.argument("path"));
CloudLabelDetector.instance.handleDetection(image, options, result);
} catch (IOException e) {
result.error("labelDetectorIOError", e.getLocalizedMessage(), null);
} catch (Exception e) {
result.error("labelDetectorError", e.getLocalizedMessage(), null);
result.error("cloudLabelDetectorIOError", e.getLocalizedMessage(), null);
}
break;
case "TextRecognizer#detectInImage":
case "TextRecognizer#processImage":
try {
image = filePathToVisionImage((String) call.argument("path"));
TextRecognizer.instance.handleDetection(image, options, result);
} catch (IOException e) {
result.error("textRecognizerIOError", e.getLocalizedMessage(), null);
} catch (Exception e) {
result.error("textRecognizerError", e.getLocalizedMessage(), null);
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ class LabelDetectorPainter extends CustomPainter {

// Paints rectangles around all the text in the image.
class TextDetectorPainter extends CustomPainter {
TextDetectorPainter(this.absoluteImageSize, this.textLocations);
TextDetectorPainter(this.absoluteImageSize, this.visionText);

final Size absoluteImageSize;
final List<TextBlock> textLocations;
final VisionText visionText;

@override
void paint(Canvas canvas, Size size) {
Expand All @@ -145,7 +145,7 @@ class TextDetectorPainter extends CustomPainter {
..style = PaintingStyle.stroke
..strokeWidth = 2.0;

for (TextBlock block in textLocations) {
for (TextBlock block in visionText.blocks) {
for (TextLine line in block.lines) {
for (TextElement element in line.elements) {
paint.color = Colors.green;
Expand All @@ -164,6 +164,6 @@ class TextDetectorPainter extends CustomPainter {
@override
bool shouldRepaint(TextDetectorPainter oldDelegate) {
return oldDelegate.absoluteImageSize != absoluteImageSize ||
oldDelegate.textLocations != textLocations;
oldDelegate.visionText != visionText;
}
}
8 changes: 4 additions & 4 deletions packages/firebase_ml_vision/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class _MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<_MyHomePage> {
File _imageFile;
Size _imageSize;
List<dynamic> _scanResults;
dynamic _scanResults;
Detector _currentDetector = Detector.text;

Future<void> _getAndScanImage() async {
Expand Down Expand Up @@ -85,21 +85,21 @@ class _MyHomePageState extends State<_MyHomePage> {
detector = FirebaseVision.instance.cloudLabelDetector();
break;
case Detector.text:
detector = FirebaseVision.instance.textDetector();
detector = FirebaseVision.instance.textRecognizer();
break;
default:
return;
}

final List<dynamic> results =
final dynamic results =
await detector.detectInImage(visionImage) ?? <dynamic>[];

setState(() {
_scanResults = results;
});
}

CustomPaint _buildResults(Size imageSize, List<dynamic> results) {
CustomPaint _buildResults(Size imageSize, dynamic results) {
CustomPainter painter;

switch (_currentDetector) {
Expand Down
16 changes: 10 additions & 6 deletions packages/firebase_ml_vision/ios/Classes/CloudLabelDetector.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ + (void)handleDetection:(FIRVisionImage *)image
}

+ (FIRVisionCloudDetectorOptions *)parseOptions:(NSDictionary *)optionsData {
FIRVisionCloudDetectorOptions *detector = [[FIRVisionCloudDetectorOptions alloc] init];

NSNumber *modelType = optionsData[@"modelType"];
detector.modelType = (FIRVisionCloudModelType)[modelType intValue];
FIRVisionCloudDetectorOptions *options = [[FIRVisionCloudDetectorOptions alloc] init];

NSNumber *maxResults = optionsData[@"maxResults"];
detector.maxResults = [maxResults unsignedIntegerValue];
options.maxResults = [maxResults unsignedIntegerValue];

NSString *modelTypeStr = optionsData[@"modelType"];
if ([@"stable" isEqualToString:modelTypeStr]) {
options.modelType = FIRVisionCloudModelTypeStable;
} else if ([@"latest" isEqualToString:modelTypeStr]) {
options.modelType = FIRVisionCloudModelTypeLatest;
}

return detector;
return options;
}
@end
Loading