-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Code cleanup and added metadata for ML Vision #631
Code cleanup and added metadata for ML Vision #631
Conversation
This PR is also missing a rebase. I'm working on rebasing it correctly. The HEAD for this branch is 9c2af92. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
FlutterFire.md
Outdated
@@ -26,6 +26,7 @@ The plugins are still under development, and some APIs might not be available ye | |||
| [firebase_performance][performance_pub] | ![pub package][performance_badge] | [Firebase Performance Monitoring][performance_product] | [`packages/firebase_performance`][performance_code] | | |||
| [firebase_remote_config][remote_config_pub] | ![pub package][remote_config_badge] | [Firebase Remote Config][remote_config_product] | [`packages/firebase_remote_config`][remote_config_code] | | |||
| [cloud_functions][functions_pub] | ![pub package][functions_badge] | [Cloud Functions][functions_product] | [`packages/cloud_functions`][functions_code] | | |||
| [firebase_ml_vision][ml_vision_pub] | ![pub package][ml_vision_badge] | [Firebase ML Kit][ml_vision_product] | [`packages/firebase_ml_vision`][ml_vision_code] | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This list is getting long. Perhaps alphabetize it?
README.md
Outdated
@@ -70,5 +70,6 @@ These are the available plugins in this repository. | |||
| [firebase_remote_config](./packages/firebase_remote_config/) | [](https://pub.dartlang.org/packages/firebase_remote_config) | | |||
| [firebase_dynamic_links](./packages/firebase_dynamic_links/) | [](https://pub.dartlang.org/packages/firebase_dynamic_links) | | |||
| [cloud_functions](./packages/cloud_functions/) | [](https://pub.dartlang.org/packages/cloud_functions) | | |||
| [firebase_ml_vision](./packages/firebase_ml_vision/) | [](https://pub.dartlang.org/packages/firebase_ml_vision) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
|
||
## Usage | ||
|
||
To use this plugin, add `firebase_ml_vision` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/). You must also configure firebase for each platform project: Android and iOS (see the example folder or https://codelabs.developers.google.com/codelabs/flutter-firebase/#4 for step by step details). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"configure firebase" => "configure Firebase"?
|
||
To use the on-device text recognition model, run the text detector as described below: | ||
|
||
1. Create a FirebaseVisionImage object from your image. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FirebaseVisionImage should be code font for consistency.
final String text = block.text; | ||
|
||
for (TextLine line in block.lines) { | ||
// .... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An ellipsis is usually three dots: // ...
try { | ||
textDetector.close(); | ||
} catch (IOException exception) { | ||
result.error("textDetectorError", exception.getLocalizedMessage(), null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we get to this code, we'll be invoking both result.error
and result.success
.
/// Due to the possible perspective distortions, this is not necessarily a | ||
/// rectangle. Parts of the region could be outside of the image. | ||
/// | ||
/// Could be empty even if text is found. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea what that means or when that happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The android implementation has the @Nullable
annotation for boundingBox()
and cornerPoints()
. I haven't found anywhere that specifies why or had it actually return null
for any of the test images. However, I added code and a comment to handle it just in case it does because I didn't want it to accidentally crash an app. Also, I get warnings from android studio to handle a null
situation.
What's interesting though, is that the iOS side marks cornerPoints()
as _NonNull
.
https://firebase.google.com/docs/reference/ios/firebasemlvision/api/reference/Protocols/FIRVisionText
.map<Point<num>>((dynamic item) => Point<num>( | ||
item[0], | ||
item[1], | ||
)) | ||
.toList(), | ||
text = data['text']; | ||
|
||
/// Axis-aligned bounding rectangle of the detected text. | ||
final Rectangle<num> boundingBox; | ||
final List<Point<num>> _cornerPoints; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we avoid num
here and just use double
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tl;dr
num => int
I decided to use num
because iOS returns double
s while android returns int
s. With further investigating though, iOS only returns double
s for bounding box because CGRect
uses double
s. So, I changed num to int to make it clearer to the user that the values will be whole numbers.
/// rectangle. Parts of the region could be outside of the image. | ||
final List<Point<num>> cornerPoints; | ||
/// Could be null even if text is found. | ||
final Rectangle<num> boundingBox; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here?
), | ||
]); | ||
|
||
expect(blocks, <TextBlock>[]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or expect(blocks, isEmpty);
No description provided.