Skip to content

Commit

Permalink
fix corner point orientation with VNBarcodeObservation
Browse files Browse the repository at this point in the history
  • Loading branch information
navaronbracke committed Nov 9, 2024
1 parent 2ac67c2 commit d9c2d1e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Bugs fixed:
* [Apple] Fixed an issue which caused the scanWindow to always be present, even when reset to no value.
* [Apple] Fixed an issue that caused the barcode size to report the wrong height.
* [Apple] Fixed a bug that caused the corner points to not be returned in clockwise orientation.

Improvements:
* Added a basic barcode overlay widget, for use with the camera preview.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,11 +814,12 @@ extension VNBarcodeObservation {
let bottomRightY = (1 - bottomRight.y) * CGFloat(imageHeight)
let bottomLeftY = (1 - bottomLeft.y) * CGFloat(imageHeight)
let data = [
// Clockwise, starting from the top-left corner.
"corners": [
["x": bottomLeftX, "y": bottomLeftY],
["x": topLeftX, "y": topLeftY],
["x": topRightX, "y": topRightY],
["x": bottomRightX, "y": bottomRightY],
["x": bottomLeftX, "y": bottomLeftY],
],
"format": symbology.toInt ?? -1,
"rawValue": payloadStringValue ?? "",
Expand Down
12 changes: 9 additions & 3 deletions lib/src/objects/barcode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,16 @@ class Barcode {
/// The contact information that is embedded in the barcode.
final ContactInfo? contactInfo;

/// The four corner points of the barcode,
/// in clockwise order, starting with the top-left point.
/// The corner points of the barcode.
///
/// Due to the possible perspective distortions, this is not necessarily a rectangle.
/// On Android, iOS and MacOS, this is a list of four points,
/// in clockwise direction, starting with the top left.
///
/// On the web, the amount of points and their order
/// is dependent on the type of barcode that was detected.
///
/// Due to the possible perspective distortions,
/// the points do not necessarily form a rectangle.
///
/// This list is empty if the corners can not be determined.
final List<Offset> corners;
Expand Down
2 changes: 2 additions & 0 deletions lib/src/web/zxing/result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ extension type Result(JSObject _) implements JSObject {

/// Convert this result to a [Barcode].
Barcode get toBarcode {
// The order of the points is dependent on the type of barcode.
// Don't do a manual correction here, but leave it up to the reader implementation.
final List<Offset> corners = resultPoints;

return Barcode(
Expand Down

0 comments on commit d9c2d1e

Please sign in to comment.