Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Add barcode detector for ML Vision #646

Merged
merged 25 commits into from
Jul 13, 2018

Conversation

azihsoyn
Copy link
Contributor

No description provided.

@azihsoyn azihsoyn changed the title [WIP] Add barcode detector for ML Vision Add barcode detector for ML Vision Jun 30, 2018
@bparrishMines bparrishMines self-requested a review July 2, 2018 16:25
visionImage.imageFile.path,
);

final List<TextBlock> blocks = <TextBlock>[];
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

@bparrishMines bparrishMines Jul 3, 2018

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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,
Copy link
Contributor

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'],

Copy link
Contributor Author

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 =
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add dartdoc documentation explaining what the class is for? Also could you add documentation for all the public variables?

Typically, you can just copy and paste the documentation used on the firebase website for Barcodes.

You can look at TextDetector as well for documentation examples.

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 got it!

: VisionBarcodeDriverLicense._(_data['driver_license']);
}

// ios:
Copy link
Contributor

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.'

Copy link
Contributor

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
Copy link
Contributor

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,
Copy link
Contributor

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 {
Copy link
Contributor

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]

@azihsoyn
Copy link
Contributor Author

azihsoyn commented Jul 3, 2018

Thank you for your kind review!

I'll fix documentation and test code!

@azihsoyn
Copy link
Contributor Author

azihsoyn commented Jul 4, 2018

Yay! I finally did it!

]);

final VisionBarcode barcode = barcodes[0];
expect(barcode.boundingBox, const Rectangle<num>(1, 2, 3, 4));
Copy link
Contributor

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?

Copy link
Contributor Author

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.
Copy link
Contributor

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?

Copy link
Contributor Author

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]:
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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?

Copy link
Contributor

@bparrishMines bparrishMines left a 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;;'.
Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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].
Copy link
Contributor

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.
Copy link
Contributor

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 {
Copy link
Contributor

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.

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 was wondering what to do about it! I fix it😁

[emails addObject:@{
@"address" : email.address,
@"body" : email.body,
@"subjec" : email.subject,
Copy link
Contributor

Choose a reason for hiding this comment

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

"subject"

Copy link
Contributor Author

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.
Copy link
Contributor

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.
Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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
Copy link
Contributor

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;
Copy link
Contributor

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.
Copy link
Contributor

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;
Copy link
Contributor

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);

@j0nscalet
Copy link

j0nscalet commented Jul 12, 2018

@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 😆)

@azihsoyn
Copy link
Contributor Author

Hi, @j0nscalet!

My unofficial library also implemented barcode detector (of course the other detector).

However, your switch is correct 😁

Copy link
Contributor

@bparrishMines bparrishMines left a comment

Choose a reason for hiding this comment

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

Good to submit

@bparrishMines bparrishMines merged commit 3edd01b into flutter:master Jul 13, 2018
@azihsoyn azihsoyn deleted the feature/barcode_detector branch July 13, 2018 00:53
@azihsoyn
Copy link
Contributor Author

Great thanks @bparrishMines!

@j0nscalet
Copy link

This is sweet! Thank you @bparrishMines and @azihsoyn for your hard work on this. Our team will put it to good use. 😄 💪

kmorkos pushed a commit to kmorkos/plugins that referenced this pull request Jul 19, 2018
julianscheel pushed a commit to jusst-engineering/plugins that referenced this pull request Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants