juliansteenbakker / mobile_scanner

A universal scanner for Flutter based on MLKit. Uses CameraX on Android and AVFoundation on iOS.
BSD 3-Clause "New" or "Revised" License
906 stars 520 forks source link

Inverted EAN-13 barcode not recognized in dark theme #1201

Open ProstoCesar opened 1 month ago

ProstoCesar commented 1 month ago

Hello, guys. I've encountered an issue where inverted (dark theme) EAN-13 barcodes are not recognized by mobile_scanner. When using a standard barcode (black bars on white background), the barcode is scanned correctly. However, when I invert the colors (white bars on black background), the scanner fails to detect the barcode. Steps:

Screenshots: Correctly recognized barcode in light theme: image Barcode not recognized in dark theme: image

Environment: mobile_scanner version: 5.2.3 Flutter version: 3.24.3 Dart version: 3.5.3 Devices: Honor 30, Pixel 8, Honor 10x Lite

alexandrim0 commented 1 month ago

Same trouble for me with QRcode.

alexandrim0 commented 1 month ago

The problem is in MLkit https://github.com/juliansteenbakker/mobile_scanner/pull/1071

navaronbracke commented 1 month ago

As reported above, this seems like an issue in MLKit that does not detect inverted barcodes.

I'll test this on MacOS, to see if the Vision API has the same issue. If MacOS does not have that issue, then this will be fixed in the next major release, that will use the Vision API on iOS as well. For Android we will look into adding support for inverted barcodes, like with the PR mentioned above.

navaronbracke commented 1 month ago

According to the docs, the Vision API reports whether a barcode was inverted, so it should support this.

https://developer.apple.com/documentation/vision/vnbarcodeobservation/iscolorinverted

This flag is only available on iOS 17 and higher, so I'm not sure if detecting inverted barcodes will work on iOS 16 and below.

yeras-is commented 1 month ago

@ProstoCesar We had the same issue and forked library to invert image before proceeding to ML Kit, feel free to check https://github.com/injil-kz/mobile_scanner_clone