From ddd4e20ac36a859c85f2adfcfe24606d03ef17d3 Mon Sep 17 00:00:00 2001 From: Edouard Marquez Date: Mon, 11 Apr 2022 17:05:34 +0200 Subject: [PATCH 1/2] Provide focus coordinates when using half image mode --- .../lib/pages/scan/ml_kit_scan_page.dart | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart b/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart index 514d1b56bdb..94dbfafb943 100644 --- a/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart +++ b/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart @@ -29,8 +29,10 @@ class MLKitScannerPageState extends State { CameraController? _controller; int _cameraIndex = 0; bool isBusy = false; + //Used when rebuilding to stop the camera bool stoppingCamera = false; + //We don't scan every image for performance reasons int frameCounter = 0; @@ -149,6 +151,7 @@ class MLKitScannerPageState extends State { try { await _controller?.initialize(); _controller?.setFocusMode(FocusMode.auto); + _controller?.setFocusPoint(_focusPoint); _controller?.lockCaptureOrientation(DeviceOrientation.portraitUp); _controller?.startImageStream(_processCameraImage); } on CameraException catch (e) { @@ -197,6 +200,26 @@ class MLKitScannerPageState extends State { isBusy = false; } + Offset? get _focusPoint { + final DevModeScanMode scanMode = DevModeScanModeExtension.fromIndex( + _userPreferences + .getDevModeIndex(UserPreferencesDevMode.userPreferencesEnumScanMode), + ); + + switch (scanMode) { + case DevModeScanMode.PREPROCESS_HALF_IMAGE: + case DevModeScanMode.SCAN_HALF_IMAGE: + // Half center top + return const Offset(0.5, 0.25); + case DevModeScanMode.CAMERA_ONLY: + case DevModeScanMode.PREPROCESS_FULL_IMAGE: + case DevModeScanMode.SCAN_FULL_IMAGE: + default: + // Center + return const Offset(0.5, 0.5); + } + } + Future _scan(final CameraImage image) async { final DevModeScanMode scanMode = DevModeScanModeExtension.fromIndex( _userPreferences From 5df70ce7cccd6f901e9baafca7500084c1a2f76f Mon Sep 17 00:00:00 2001 From: Edouard Marquez Date: Mon, 11 Apr 2022 17:08:50 +0200 Subject: [PATCH 2/2] Ensure to wait all Futures --- .../smooth_app/lib/pages/scan/ml_kit_scan_page.dart | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart b/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart index 94dbfafb943..4b55a85056f 100644 --- a/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart +++ b/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart @@ -64,8 +64,6 @@ class MLKitScannerPageState extends State { ), ); } - - _startLiveFeed(); } @override @@ -150,10 +148,10 @@ class MLKitScannerPageState extends State { try { await _controller?.initialize(); - _controller?.setFocusMode(FocusMode.auto); - _controller?.setFocusPoint(_focusPoint); - _controller?.lockCaptureOrientation(DeviceOrientation.portraitUp); - _controller?.startImageStream(_processCameraImage); + await _controller?.setFocusMode(FocusMode.auto); + await _controller?.setFocusPoint(_focusPoint); + await _controller?.lockCaptureOrientation(DeviceOrientation.portraitUp); + await _controller?.startImageStream(_processCameraImage); } on CameraException catch (e) { if (kDebugMode) { // TODO(M123): Show error message