Skip to content

Commit d9c2d1e

Browse files
committed
fix corner point orientation with VNBarcodeObservation
1 parent 2ac67c2 commit d9c2d1e

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Bugs fixed:
99
* [Apple] Fixed an issue which caused the scanWindow to always be present, even when reset to no value.
1010
* [Apple] Fixed an issue that caused the barcode size to report the wrong height.
11+
* [Apple] Fixed a bug that caused the corner points to not be returned in clockwise orientation.
1112

1213
Improvements:
1314
* Added a basic barcode overlay widget, for use with the camera preview.

darwin/mobile_scanner/Sources/mobile_scanner/MobileScannerPlugin.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,11 +814,12 @@ extension VNBarcodeObservation {
814814
let bottomRightY = (1 - bottomRight.y) * CGFloat(imageHeight)
815815
let bottomLeftY = (1 - bottomLeft.y) * CGFloat(imageHeight)
816816
let data = [
817+
// Clockwise, starting from the top-left corner.
817818
"corners": [
818-
["x": bottomLeftX, "y": bottomLeftY],
819819
["x": topLeftX, "y": topLeftY],
820820
["x": topRightX, "y": topRightY],
821821
["x": bottomRightX, "y": bottomRightY],
822+
["x": bottomLeftX, "y": bottomLeftY],
822823
],
823824
"format": symbology.toInt ?? -1,
824825
"rawValue": payloadStringValue ?? "",

lib/src/objects/barcode.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,16 @@ class Barcode {
102102
/// The contact information that is embedded in the barcode.
103103
final ContactInfo? contactInfo;
104104

105-
/// The four corner points of the barcode,
106-
/// in clockwise order, starting with the top-left point.
105+
/// The corner points of the barcode.
107106
///
108-
/// Due to the possible perspective distortions, this is not necessarily a rectangle.
107+
/// On Android, iOS and MacOS, this is a list of four points,
108+
/// in clockwise direction, starting with the top left.
109+
///
110+
/// On the web, the amount of points and their order
111+
/// is dependent on the type of barcode that was detected.
112+
///
113+
/// Due to the possible perspective distortions,
114+
/// the points do not necessarily form a rectangle.
109115
///
110116
/// This list is empty if the corners can not be determined.
111117
final List<Offset> corners;

lib/src/web/zxing/result.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ extension type Result(JSObject _) implements JSObject {
7575

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

8082
return Barcode(

0 commit comments

Comments
 (0)