Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(barcode-scanning): support cornerPoints in readBarcodesFromImage(...) #100

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ public static JSObject createBarcodeResultForBarcode(@NonNull Barcode barcode, @
cornerPointsResult.put(cornerPointResult);
}
}

else if (cornerPoints != null) {
Copy link
Member

Choose a reason for hiding this comment

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

This also affects the scan(...) method and leads to invalid values there, as these would have to be normalized.
For now, my suggestion is to make this dependent on the screenSize parameter. If this parameter is set, corner points may only be returned normalized. I will improve this later.

Suggested change
else if (cornerPoints != null) {
else if (cornerPoints != null && screenSize == null) {

Make sure that the screenSize parameter is null only for the readBarcodesFromImage(...) method.
Please also apply this to iOS.

for (int i = 0; i < cornerPoints.length; i++) {
JSArray cornerPointResult = new JSArray();
cornerPointResult.put(cornerPoints[i].x);
cornerPointResult.put(cornerPoints[i].y);
cornerPointsResult.put(cornerPointResult);
}
}
JSObject result = new JSObject();
result.put("bytes", convertByteArrayToJsonArray(barcode.getRawBytes()));
if (cornerPoints != null) {
Expand Down
1 change: 1 addition & 0 deletions packages/barcode-scanning/ios/Plugin/BarcodeScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ typealias MLKitBarcodeScanner = MLKitBarcodeScanning.BarcodeScanner
}
CAPLog.print("\(features?.count ?? 0)")
guard let features = features, !features.isEmpty else {
completion(features, nil)
return
}
completion(features, nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ public class BarcodeScannerHelper {
cornerPointsResult.append(value)
}
}

else if let cornerPoints = barcode.cornerPoints {
for cornerPoint in cornerPoints {
var value = [Int]()
value.append(Int(cornerPoint.cgPointValue.x))
value.append(Int(cornerPoint.cgPointValue.y))
cornerPointsResult.append(value)
}
}
var result = JSObject()
if let rawData = barcode.rawData {
result["bytes"] = convertDataToJsonArray(rawData)
Expand Down
2 changes: 1 addition & 1 deletion packages/barcode-scanning/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@capacitor-mlkit/barcode-scanning",
"version": "5.3.0",
"version": "5.3.1",
Copy link
Member

Choose a reason for hiding this comment

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

Please revert this change.

"description": "Capacitor plugin for ML Kit Barcode Scanning.",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
Expand Down