I'm trying to implement a camera-based barcode sca...
# android
l
I'm trying to implement a camera-based barcode scanner on Android (using CameraX and MLKit). I want to limit the recognized barcodes to a viewfinder frame in the center of the screen, but the returned bounding box has quite weird coordinates, and I don't know how to convert them to match the viewfinder coordinates. The viewfinder view (and the whole camera screen) is in Compose.
c
Better try in #compose-android
r
try LifecycleCameraController and wrap you analyzer in MlkitAnalyzer, this may help you with coordinates transformation.
l
Thank you, I will try this!
Turned out indeed using
LifecycleCameraController
and
MlKitAnalyzer
with
CameraController.COORDINATE_SYSTEM_VIEW_REFERENCED
fixed the problem! Then (I'm using Compose) I just had to translate the pixel coordinates from the camera to
dp
units using
LocalDensity.current
. Thanks again for your valuable suggestion. Also this article explains very well the separation of responsibilities in CameraX between
PreviewView
and `CameraController`: https://medium.com/androiddevelopers/camerax-learn-how-to-use-cameracontroller-e3ed10fffecf
Example solution in Compose in this StackOverflow answer: https://stackoverflow.com/a/77698616/4990683
r
I'm glad it helped you resolve the issue! Thanks for sharing your experience.
🙏 1