barcode-scanner icon indicating copy to clipboard operation
barcode-scanner copied to clipboard

[ML-Kit] iOS cornerPoints are not correctly translated

Open peitschie opened this issue 2 years ago • 1 comments

Describe the bug The cornerPoints returned on iOS don't render properly on to the web view coordinate space.

Digging further, I suspect this is because the video capture dimensions are 1080x1920 (as confirmed by looking at the AVCaptureOutput in the plugin's captureOutput func). The points are currently being divided by the screen scale (2.0, based on a real resolution of 750 x 1334), but I don't think this is correct:

https://github.com/capacitor-community/barcode-scanner/blob/ml-kit/ios/Plugin/Plugin.swift#L462

To get the points to render properly for me, I needed to multiply them by the screen's real dimensions (750 x 1334), and then divide by the capture dimensions (1080x1920). The resulting ratio is roughly 0.7, which makes the points render correctly on screen.

This makes sense to me because the bottom right corner will return a point of (1080,1920), which maps down to (750,1334) at the native resolution, and maps down further to (375,667) within the webview (due to the devicePixelRatio being 2)

peitschie avatar Mar 30 '23 03:03 peitschie

I am aware of this, thank you for creating the issue anyways so we can keep track of it. :)

Had the same problems when testing and starting to implement a proper scaling. It was working so far, my only issue was that I was not able to set the image orientation properly which resulted in the issue, that as soon as you switched from portrait to landscape the wrong cornerPoints where returned.

thegnuu avatar Mar 30 '23 11:03 thegnuu