-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Add barcode detector for ML Vision #646
Add barcode detector for ML Vision #646
Conversation
visionImage.imageFile.path, | ||
); | ||
|
||
final List<TextBlock> 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.
I believe you want List<VisionBarcode> barcodes <VisionBarcode>[];
right?
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.
Woops... It's my fault.
return; | ||
} | ||
|
||
// Scaned barcode |
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.
Small nitpick:
"Scanned"
static FIRVisionBarcodeDetector *barcodeDetector; | ||
|
||
+ (void)handleDetection:(FIRVisionImage *)image result:(FlutterResult)result { | ||
if (barcodeDetector == nil) { |
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.
Small nitpick:
I believe if (barcodeDetector) {
should work.
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.
Did you mean if (!barcodeDetector) {
?
final VisionBarcodeCalendarEvent calendarEvent; | ||
final VisionBarcodeDriverLicense driverLicense; | ||
|
||
VisionBarcode._(Map<dynamic, dynamic> _data) |
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.
Typically, we place the constructor at the top of the class in dart.
_data['width'], | ||
_data['height'], | ||
), | ||
rawValue = _data['raw_value'] != null ? _data['raw_value'] : 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 you're aim is to set rawValue to null
if _data['raw_value']
equals null. I believe you can just use the line rawValue = _data['raw_value'],
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.
You are right!
_data['height'], | ||
), | ||
rawValue = _data['raw_value'] != null ? _data['raw_value'] : null, | ||
displayValue = |
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 as rawValue
} | ||
} | ||
|
||
class BarcodeDetectorOptions {} | ||
class VisionBarcode { |
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.
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.
I got it!
: VisionBarcodeDriverLicense._(_data['driver_license']); | ||
} | ||
|
||
// ios: |
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.
Instead of the links, you can just copy and paste their documentation, such as
'This option specifies the barcode formats that the library should detect.'
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.
Also Dartdoc documentation uses ///
instead of //
// ios | ||
// https://firebase.google.com/docs/reference/ios/firebasemlvision/api/reference/Classes/FIRVisionBarcodeEmail | ||
// android | ||
// https://firebase.google.com/docs/reference/android/com/google/firebase/ml/vision/barcode/FirebaseVisionBarcode.Email |
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 as VisionBarcodeFormat documentation comment
class VisionBarcodeEmail { | ||
VisionBarcodeEmail._(Map<dynamic, dynamic> data) | ||
: type = VisionBarcodeEmailType.values.elementAt(data['type']), | ||
address = data['address'] != null ? data['address'] : 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.
For address
, body
, and subject
. You should just be able to use variableName = data['variableName']
final VisionBarcodeEmailType type; | ||
} | ||
|
||
enum VisionBarcodeEmailType { |
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 you add a little documentation for the enums in the class as well. The enum is straight forward so you could just simply use /// The type of email for [VisionBarcodeEmail]
Thank you for your kind review! I'll fix documentation and test code! |
Yay! I finally did it! |
]); | ||
|
||
final VisionBarcode barcode = barcodes[0]; | ||
expect(barcode.boundingBox, const Rectangle<num>(1, 2, 3, 4)); |
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 should be Rectangle<int>
, right? Can you change all the Point<num>
to Point<int>
as well?
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.
Yes. I referred TextDetector test. (https://github.com/flutter/plugins/blob/master/packages/firebase_ml_vision/test/firebase_ml_vision_test.dart#L100)
@@ -4,18 +4,599 @@ | |||
|
|||
part of firebase_ml_vision; | |||
|
|||
/// Detector for performing optical character recognition(OCR) on an input 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.
I believe this was copied from the TextDetector. Can you update this for the barcode detector?
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.
😱
@@ -4,18 +4,599 @@ | |||
|
|||
part of firebase_ml_vision; | |||
|
|||
/// Detector for performing optical character recognition(OCR) on an input image. | |||
/// | |||
/// A barcode detector is created via getVisionBarcodeDetector() in [FirebaseVision]: |
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.
barcodeDetector()
|
||
/// Closes the barcode detector and release its model resources. |
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.
'release' => 'releases'. I made the same mistake on TextDetector :)
} | ||
|
||
/// Detects barcode in the input image. | ||
/// | ||
/// The OCR is performed asynchronously. |
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.
Does the barcode detector use OCR?
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 tests look great! I added more comments mainly discussing some small documentation changes.
final Rectangle<int> boundingBox; | ||
|
||
/// Returns barcode value as it was encoded in the barcode. | ||
/// Structured values are not parsed, for example: 'MEBKM:TITLE:Google;URL://www.google.com;;'. |
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.
Leave a space between the top comment and the rest of the comments. Effective dartdocs Do the same for similar comments below.
/// Returns null if nothing found. | ||
final String rawValue; | ||
|
||
/// Returns barcode value in a user-friendly format. |
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.
Since this is a variable, I believe it is better to say The barcode value in a user-friendly format.
Returns implies that it is a method. Same for similar comments on variables below.
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.
You're right.
/// and implement your own parsing logic. | ||
final VisionBarcodeValueType valueType; | ||
|
||
/// Gets parsed email details (set iff [valueType] is [VisionBarcodeValueType.Email]. |
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.
Missing closing parentheses at the end. You can remove Gets
and just have Parsed email details ...
body = data['body'], | ||
subject = data['subject']; | ||
|
||
/// Gets email's address. |
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.
Remove Gets
. Same for body
and subject
Using The email's address
would be a good choice.
} | ||
} | ||
|
||
class BarcodeDetectorOptions {} | ||
/// Represents a single recognized barcode and its value. | ||
class VisionBarcode { |
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.
I think using Barcode
rather than VisionBarcode
would be sufficient. It would also match the other Detectors.
I think you can remove Vision
from all the other classes as well, since it makes the class names longer, but does not help in terms of clarity.
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.
I was wondering what to do about it! I fix it😁
[emails addObject:@{ | ||
@"address" : email.address, | ||
@"body" : email.body, | ||
@"subjec" : email.subject, |
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.
"subject"
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.
oops...
? null | ||
: BarcodeDriverLicense._(_data['driver_license']); | ||
|
||
/// Gets the bounding rectangle of the detected barcode. |
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.
I think you forgot to remove this "Gets"
/// Returns null if the bounding rectangle can not be determined. | ||
final Rectangle<int> boundingBox; | ||
|
||
/// Returns barcode value as it was encoded in the barcode. |
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.
I think you forgot to remove this "Returns"
/// Barcode format constants - enumeration of supported barcode formats. | ||
class BarcodeFormat { | ||
final int value; | ||
const BarcodeFormat._(this.value); |
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.
nitpicky: Constructor should be at the top.
|
||
/// Barcode format constants - enumeration of supported barcode formats. | ||
class BarcodeFormat { | ||
final int value; |
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.
Forgot comment for this variable.
BarcodeWiFiEncryptionType.values.elementAt(data['encryption_type']); | ||
|
||
final String ssid; | ||
final String password; |
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.
Can you include comments for ssid
and password
variables?
final String ssid; | ||
final String password; | ||
|
||
/// Gets the encryption type of the WIFI |
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.
"Gets"
: latitude = data['latitude'], | ||
longitude = data['longitude']; | ||
final double latitude; | ||
final double longitude; |
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.
Can you include comments for latitude
and longitude
variables?
jobTitle = data['job_title'], | ||
organization = data['organization']; | ||
|
||
/// Gets contact person's addresses. |
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.
You use Gets
for the variables in this class and all the classes below this one.
/// The four corner points in clockwise direction starting with top-left. | ||
/// | ||
/// Due to the possible perspective distortions, this is not necessarily a rectangle. | ||
final List<Point<int>> 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.
For the classes that use a List
variable, we don't want the user to be able to modify the list. final
only keeps cornerPoints
from being assigned a new List
.
I typically just create a new list with a getter:
final List<Point<int>> _cornerPoints;
List<Point<int>> get cornerPoints => List<Point<int>>.from(_cornerPoints);
@azihsoyn Happy to help with this if need be, based on the review looks like it's on the 5 yard line though. (Been using your unofficial library, made to switch the the official one, only to realize barcode detector is not implemented 😆) |
Hi, @j0nscalet! My unofficial library also implemented barcode detector (of course the other detector). However, your switch is correct 😁 |
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.
Good to submit
Great thanks @bparrishMines! |
This is sweet! Thank you @bparrishMines and @azihsoyn for your hard work on this. Our team will put it to good use. 😄 💪 |
No description provided.