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

feat: Half image focus #1579

Merged
merged 2 commits into from
Apr 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class MLKitScannerPageState extends State<MLKitScannerPage> {
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;

Expand Down Expand Up @@ -62,8 +64,6 @@ class MLKitScannerPageState extends State<MLKitScannerPage> {
),
);
}

_startLiveFeed();
}

@override
Expand Down Expand Up @@ -148,9 +148,10 @@ class MLKitScannerPageState extends State<MLKitScannerPage> {

try {
await _controller?.initialize();
_controller?.setFocusMode(FocusMode.auto);
_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
Expand Down Expand Up @@ -197,6 +198,26 @@ class MLKitScannerPageState extends State<MLKitScannerPage> {
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<void> _scan(final CameraImage image) async {
final DevModeScanMode scanMode = DevModeScanModeExtension.fromIndex(
_userPreferences
Expand Down