Skip to content

Commit 97e1837

Browse files
authored
Merge pull request #144 from rushio-consulting/bugfix/cameraDistortion
Bugfix/camera distortion
2 parents 69920c8 + c889728 commit 97e1837

File tree

6 files changed

+88
-50
lines changed

6 files changed

+88
-50
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [3.0.1] - 30/04/2021
2+
3+
- update deps
4+
- fix camera distortion
5+
16
## [3.0.0] - 17/04/2021
27

38
- migrate to null safety

example/lib/main_live.dart

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,21 @@ class _MyHomePageState extends State<MyHomePage> {
6464
child: Column(
6565
mainAxisSize: MainAxisSize.min,
6666
children: [
67-
ConstrainedBox(
68-
constraints: BoxConstraints(maxHeight: 250),
69-
child: Scrollbar(
70-
child: ListView(
71-
children: data.map((d) {
72-
return Container(
73-
color: Color(0xAAFFFFFF),
74-
child: Padding(
75-
padding: const EdgeInsets.all(16),
76-
child: Text(d),
77-
),
78-
);
79-
}).toList(),
67+
Expanded(
68+
child: ConstrainedBox(
69+
constraints: BoxConstraints(maxHeight: 250),
70+
child: Scrollbar(
71+
child: ListView(
72+
children: data.map((d) {
73+
return Container(
74+
color: Color(0xAAFFFFFF),
75+
child: Padding(
76+
padding: const EdgeInsets.all(16),
77+
child: Text(d),
78+
),
79+
);
80+
}).toList(),
81+
),
8082
),
8183
),
8284
),

example/pubspec.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ packages:
112112
name: firebase_core
113113
url: "https://pub.dartlang.org"
114114
source: hosted
115-
version: "1.0.3"
115+
version: "1.1.0"
116116
firebase_core_platform_interface:
117117
dependency: transitive
118118
description:
@@ -133,7 +133,7 @@ packages:
133133
name: firebase_ml_vision
134134
url: "https://pub.dartlang.org"
135135
source: hosted
136-
version: "0.12.0"
136+
version: "0.12.0+1"
137137
flutter:
138138
dependency: "direct main"
139139
description: flutter
@@ -145,7 +145,7 @@ packages:
145145
path: ".."
146146
relative: true
147147
source: path
148-
version: "3.0.0"
148+
version: "3.0.0+1"
149149
flutter_test:
150150
dependency: "direct dev"
151151
description: flutter

lib/flutter_camera_ml_vision.dart

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export 'package:camera/camera.dart';
1919
part 'utils.dart';
2020

2121
typedef HandleDetection<T> = Future<T> Function(FirebaseVisionImage image);
22-
typedef ErrorWidgetBuilder = Widget Function(BuildContext context, CameraError error);
22+
typedef ErrorWidgetBuilder = Widget Function(
23+
BuildContext context, CameraError error);
2324

2425
enum CameraError {
2526
unknown,
@@ -111,7 +112,6 @@ class CameraMlVisionState<T> extends State<CameraMlVision<T>>
111112
} on PlatformException catch (e) {
112113
debugPrint('$e');
113114
}
114-
115115
}
116116
}
117117

@@ -174,6 +174,34 @@ class CameraMlVisionState<T> extends State<CameraMlVision<T>>
174174
return image;
175175
}
176176

177+
Future<void> flash(FlashMode mode) async {
178+
await _cameraController!.setFlashMode(mode);
179+
}
180+
181+
Future<void> focus(FocusMode mode) async {
182+
await _cameraController!.setFocusMode(mode);
183+
}
184+
185+
Future<void> focusPoint(Offset point) async {
186+
await _cameraController!.setFocusPoint(point);
187+
}
188+
189+
Future<void> zoom(double zoom) async {
190+
await _cameraController!.setZoomLevel(zoom);
191+
}
192+
193+
Future<void> exposure(ExposureMode mode) async {
194+
await _cameraController!.setExposureMode(mode);
195+
}
196+
197+
Future<void> exposureOffset(double offset) async {
198+
await _cameraController!.setExposureOffset(offset);
199+
}
200+
201+
Future<void> exposurePoint(Offset offset) async {
202+
await _cameraController!.setExposurePoint(offset);
203+
}
204+
177205
Future<void> _initialize() async {
178206
if (Platform.isAndroid) {
179207
final deviceInfo = DeviceInfoPlugin();
@@ -267,22 +295,25 @@ class CameraMlVisionState<T> extends State<CameraMlVision<T>>
267295
: widget.errorBuilder!(context, _cameraError);
268296
}
269297

270-
Widget cameraPreview = AspectRatio(
271-
aspectRatio: _cameraController!.value.isInitialized ? _cameraController!
272-
.value.aspectRatio : 1,
273-
child: _isStreaming
274-
? CameraPreview(
275-
_cameraController!,
276-
)
277-
: _getPicture(),
278-
);
298+
var cameraPreview = _isStreaming
299+
? CameraPreview(
300+
_cameraController!,
301+
)
302+
: _getPicture();
279303

280304
if (widget.overlayBuilder != null) {
281305
cameraPreview = Stack(
282306
fit: StackFit.passthrough,
283307
children: [
284308
cameraPreview,
285-
widget.overlayBuilder!(context),
309+
(cameraController?.value.isInitialized ?? false)
310+
? AspectRatio(
311+
aspectRatio: _isLandscape()
312+
? cameraController!.value.aspectRatio
313+
: (1 / cameraController!.value.aspectRatio),
314+
child: widget.overlayBuilder!(context),
315+
)
316+
: Container(),
286317
],
287318
);
288319
}
@@ -299,25 +330,28 @@ class CameraMlVisionState<T> extends State<CameraMlVision<T>>
299330
}
300331
},
301332
key: _visibilityKey,
302-
child: FittedBox(
303-
alignment: Alignment.center,
304-
fit: BoxFit.cover,
305-
child: SizedBox(
306-
width: _cameraController!.value.previewSize!.height *
307-
_cameraController!.value.aspectRatio,
308-
height: _cameraController!.value.previewSize!.height,
309-
child: cameraPreview,
310-
),
311-
),
333+
child: cameraPreview,
312334
);
313335
}
314336

337+
DeviceOrientation? _getApplicableOrientation() {
338+
return (cameraController?.value.isRecordingVideo ?? false)
339+
? cameraController?.value.recordingOrientation
340+
: (cameraController?.value.lockedCaptureOrientation ??
341+
cameraController?.value.deviceOrientation);
342+
}
343+
344+
bool _isLandscape() {
345+
return [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]
346+
.contains(_getApplicableOrientation());
347+
}
348+
315349
void _processImage(CameraImage cameraImage) async {
316350
if (!_alreadyCheckingImage && mounted) {
317351
_alreadyCheckingImage = true;
318352
try {
319353
final results =
320-
await _detect<T>(cameraImage, widget.detector, _rotation!);
354+
await _detect<T>(cameraImage, widget.detector, _rotation!);
321355
widget.onResult(results);
322356
} catch (ex, stack) {
323357
debugPrint('$ex, $stack');

pubspec.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ packages:
5151
source: hosted
5252
version: "1.1.0"
5353
collection:
54-
dependency: transitive
54+
dependency: "direct main"
5555
description:
5656
name: collection
5757
url: "https://pub.dartlang.org"
@@ -105,7 +105,7 @@ packages:
105105
name: firebase_core
106106
url: "https://pub.dartlang.org"
107107
source: hosted
108-
version: "1.0.3"
108+
version: "1.1.0"
109109
firebase_core_platform_interface:
110110
dependency: transitive
111111
description:
@@ -126,7 +126,7 @@ packages:
126126
name: firebase_ml_vision
127127
url: "https://pub.dartlang.org"
128128
source: hosted
129-
version: "0.12.0"
129+
version: "0.12.0+1"
130130
flutter:
131131
dependency: "direct main"
132132
description: flutter

pubspec.yaml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
name: flutter_camera_ml_vision
22
description: A flutter widget that show the camera stream and allow ML vision recognition on it, it allow you to detect barcodes, labels, text, faces...
3-
version: 3.0.0
4-
authors:
5-
- Jimmy Aumard <jimmy.aumard@gmail.com>
6-
- Rushio Consulting <dev@rushio-consulting.fr>
3+
version: 3.0.1
74
repository: https://github.com/rushio-consulting/flutter_camera_ml_vision
8-
homepage: https://rushio-consulting.fr
5+
homepage: https://github.com/rushio-consulting/flutter_camera_ml_vision
96

107
environment:
118
sdk: '>=2.12.0 <3.0.0'
129

1310
dependencies:
1411
flutter:
1512
sdk: flutter
16-
firebase_ml_vision: ^0.12.0
13+
firebase_ml_vision: ^0.12.0+1
1714
#git:
1815
# url: git://github.com/algirdasmac/flutterfire
1916
# path: packages/firebase_ml_vision
20-
firebase_core: ^1.0.3
21-
#firebase_ml_vision: ^0.12.0
17+
firebase_core: ^1.1.0
2218
visibility_detector: ^0.2.0
2319
path_provider: ^2.0.1
2420
pedantic: ^1.11.0
2521
device_info: ^2.0.0
2622
camera: ^0.8.1
23+
collection: ^1.15.0
2724

2825
dev_dependencies:
2926
flutter_test:

0 commit comments

Comments
 (0)