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

fix: support formats for analyze image #1177

Merged
merged 18 commits into from
Sep 10, 2024

Conversation

navaronbracke
Copy link
Collaborator

@navaronbracke navaronbracke commented Sep 10, 2024

This PR adds support for specifying the formats for analyze image.

It also adds the (normalized) barcode size for the barcodes on the web and adds support for analyze image on MacOS.

Fixes #1069

| analyzeImage (Gallery) | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
| returnImage | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: |
| analyzeImage (Gallery) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| returnImage | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forgot to update this one for returnImage

@@ -134,16 +134,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin {
self.mobileScanner.timeoutSeconds = Double(timeoutMs) / Double(1000)
MobileScannerPlugin.returnImage = returnImage

let formatList = formats.map { format in return BarcodeFormat(rawValue: format)}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was refactored & moved to reuse it

"rawValue": self.payloadStringValue ?? "",
"format": self.symbology.toInt ?? -1,
"corners": [
["x": topLeft.x, "y": topLeft.y],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The VNBarcodeResult had these corner points, but we did not pass them through

let symbologies:[VNBarcodeSymbology] = argReader.toSymbology()

guard let fileUrl: URL = URL(string: argReader.string(key: "filePath") ?? "") else {
// TODO: fix error code
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will unify the error codes in a follow up PR

formats.removeWhere((element) => element == BarcodeFormat.unknown);
}
final List<BarcodeFormat> formats = [
for (final BarcodeFormat format in options.formats)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

for literal to optimize away the remove where

return const SizedBox();
}

return CustomPaint(
painter: BarcodeOverlay(
barcodeCorners: scannedBarcode.corners,
barcodeSize: barcodeCapture.size,
barcodeSize: scannedBarcode.size,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The "barcode size" is wrong here

@@ -151,28 +151,16 @@ class MobileScannerHandler(
null
}

var barcodeScannerOptions: BarcodeScannerOptions? = null
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was refactored & moved to reuse it.


val position =
if (facing == 0) CameraSelector.DEFAULT_FRONT_CAMERA else CameraSelector.DEFAULT_BACK_CAMERA

val detectionSpeed: DetectionSpeed = if (speed == 0) DetectionSpeed.NO_DUPLICATES
else if (speed ==1) DetectionSpeed.NORMAL else DetectionSpeed.UNRESTRICTED
val detectionSpeed: DetectionSpeed = when (speed) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a refactor that was proposed by the Kotlin language tooling

/// Barcode scanner for results
var scanner = BarcodeScanner.barcodeScanner()
/// The long lived barcode scanner for scanning barcodes from a camera preview.
var scanner: BarcodeScanner? = nil
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a bit weird. We never deallocated the scanner for iOS.

This is similar to #988 and possibly related to #862

let image = VisionImage(image: image)
image.orientation = imageOrientation(
deviceOrientation: UIDevice.current.orientation,
defaultOrientation: .portrait,
position: position
)

let scanner: BarcodeScanner = barcodeScannerOptions != nil ? BarcodeScanner.barcodeScanner(options: barcodeScannerOptions!) : BarcodeScanner.barcodeScanner()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Create a short lived scanner for the analyze image call

@navaronbracke navaronbracke merged commit ad0071d into juliansteenbakker:master Sep 10, 2024
5 checks passed
@navaronbracke navaronbracke deleted the macos_extras branch September 10, 2024 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with MobileScannerController: Recognizes Unspecified Formats
1 participant