diff --git a/example/.gitignore b/example/.gitignore index 3c3ed63..6eb40c5 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -31,6 +31,7 @@ **/android/**/gradle-wrapper.jar **/android/.gradle **/android/captures/ +**/android/app/google-services.json **/android/gradlew **/android/gradlew.bat **/android/local.properties diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 456484e..517a5c5 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -22,10 +22,11 @@ if (flutterVersionName == null) { } apply plugin: 'com.android.application' +apply plugin: 'com.google.gms.google-services' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 28 + compileSdkVersion 29 lintOptions { disable 'InvalidPackage' @@ -33,9 +34,9 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "fr.rushioconsulting.flutter_camera_ml_vision_example" - minSdkVersion 21 - targetSdkVersion 28 + applicationId "com.android.flutter_camera_ml_example" + minSdkVersion 29 + targetSdkVersion 29 versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -55,7 +56,8 @@ flutter { } dependencies { - api 'com.google.firebase:firebase-ml-vision-barcode-model:16.1.2' + implementation platform('com.google.firebase:firebase-bom:29.0.1') + api 'com.google.mlkit:barcode-scanning:17.0.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 62f8934..fe25c03 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -8,7 +8,6 @@ additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. --> + runApp(MyApp()); @@ -55,7 +55,7 @@ class _MyHomePageState extends State { } setState(() { - data.add(barcode.displayValue); + data.add(barcode.value.displayValue); }); }, child: Text('Scan product'), @@ -78,7 +78,7 @@ class ScanPage extends StatefulWidget { class _ScanPageState extends State { bool resultSent = false; - BarcodeDetector detector = FirebaseVision.instance.barcodeDetector(); + BarcodeScanner detector = GoogleMlKit.vision.barcodeScanner(); @override Widget build(BuildContext context) { @@ -97,7 +97,7 @@ class _ScanPageState extends State { ), ); }, - detector: detector.detectInImage, + detector: detector.processImage, onResult: (List barcodes) { if (!mounted || resultSent || diff --git a/example/lib/main_face.dart b/example/lib/main_face.dart index 805eaf1..bf10272 100644 --- a/example/lib/main_face.dart +++ b/example/lib/main_face.dart @@ -1,7 +1,6 @@ -import 'package:camera/camera.dart'; -import 'package:firebase_ml_vision/firebase_ml_vision.dart'; import 'package:flutter/material.dart'; import 'package:flutter_camera_ml_vision/flutter_camera_ml_vision.dart'; +import 'package:google_ml_kit/google_ml_kit.dart'; void main() => runApp(MyApp()); @@ -31,8 +30,7 @@ class _MyHomePageState extends State { List _faces = []; final _scanKey = GlobalKey(); CameraLensDirection cameraLensDirection = CameraLensDirection.front; - FaceDetector detector = - FirebaseVision.instance.faceDetector(FaceDetectorOptions( + FaceDetector detector = GoogleMlKit.vision.faceDetector(FaceDetectorOptions( enableTracking: true, mode: FaceDetectorMode.accurate, )); diff --git a/example/lib/main_live.dart b/example/lib/main_live.dart index 4b0d214..135e63c 100644 --- a/example/lib/main_live.dart +++ b/example/lib/main_live.dart @@ -1,6 +1,6 @@ -import 'package:firebase_ml_vision/firebase_ml_vision.dart'; import 'package:flutter/material.dart'; import 'package:flutter_camera_ml_vision/flutter_camera_ml_vision.dart'; +import 'package:google_ml_kit/google_ml_kit.dart'; void main() => runApp(MyApp()); @@ -29,7 +29,7 @@ class MyHomePage extends StatefulWidget { class _MyHomePageState extends State { List data = []; final _scanKey = GlobalKey(); - BarcodeDetector detector = FirebaseVision.instance.barcodeDetector(); + BarcodeScanner detector = GoogleMlKit.vision.barcodeScanner(); @override Widget build(BuildContext context) { @@ -42,17 +42,17 @@ class _MyHomePageState extends State { children: [ CameraMlVision>( key: _scanKey, - detector: detector.detectInImage, + detector: detector.processImage, resolution: ResolutionPreset.high, onResult: (barcodes) { if (barcodes == null || barcodes.isEmpty || - data.contains(barcodes.first.displayValue) || + data.contains(barcodes.first.value.displayValue) || !mounted) { return; } setState(() { - data.add(barcodes.first.displayValue); + data.add(barcodes.first.value.displayValue); }); }, onDispose: () { diff --git a/example/pubspec.lock b/example/pubspec.lock index aff02c6..f249575 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -21,28 +21,35 @@ packages: name: camera url: "https://pub.dartlang.org" source: hosted - version: "0.8.1" + version: "0.9.4+5" camera_platform_interface: dependency: transitive description: name: camera_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.1" + camera_web: + dependency: transitive + description: + name: camera_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.1+1" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -63,28 +70,28 @@ packages: name: cross_file url: "https://pub.dartlang.org" source: hosted - version: "0.3.1+1" + version: "0.3.2" cupertino_icons: dependency: "direct main" description: name: cupertino_icons url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "1.0.4" device_info: dependency: transitive description: name: device_info url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.3" device_info_platform_interface: dependency: transitive description: name: device_info_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" fake_async: dependency: transitive description: @@ -98,42 +105,35 @@ packages: name: ffi url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.1.2" file: dependency: transitive description: name: file url: "https://pub.dartlang.org" source: hosted - version: "6.1.0" + version: "6.1.2" firebase_core: dependency: transitive description: name: firebase_core url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.10.5" firebase_core_platform_interface: dependency: transitive description: name: firebase_core_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "4.2.2" firebase_core_web: dependency: transitive description: name: firebase_core_web url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" - firebase_ml_vision: - dependency: transitive - description: - name: firebase_ml_vision - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.0+1" + version: "1.5.2" flutter: dependency: "direct main" description: flutter @@ -145,7 +145,14 @@ packages: path: ".." relative: true source: path - version: "3.0.0+1" + version: "3.0.1" + flutter_plugin_android_lifecycle: + dependency: transitive + description: + name: flutter_plugin_android_lifecycle + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" flutter_test: dependency: "direct dev" description: flutter @@ -156,6 +163,13 @@ packages: description: flutter source: sdk version: "0.0.0" + google_ml_kit: + dependency: transitive + description: + name: google_ml_kit + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.3" js: dependency: transitive description: @@ -169,14 +183,14 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.11" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" path: dependency: transitive description: @@ -190,70 +204,84 @@ packages: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.8" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.9" + path_provider_ios: + dependency: transitive + description: + name: path_provider_ios + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.7" path_provider_linux: dependency: transitive description: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.4" path_provider_macos: dependency: transitive description: name: path_provider_macos url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.4" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.4" pedantic: dependency: transitive description: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.11.0" + version: "1.11.1" platform: dependency: transitive description: name: platform url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.1.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.2" process: dependency: transitive description: name: process url: "https://pub.dartlang.org" source: hosted - version: "4.2.1" + version: "4.2.4" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "3.0.1" + version: "3.0.1+1" sky_engine: dependency: transitive description: flutter @@ -265,7 +293,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -307,7 +335,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.4.3" typed_data: dependency: transitive description: @@ -321,21 +349,21 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" visibility_detector: dependency: transitive description: name: visibility_detector url: "https://pub.dartlang.org" source: hosted - version: "0.2.0" + version: "0.2.2" win32: dependency: transitive description: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.3.1" xdg_directories: dependency: transitive description: @@ -344,5 +372,5 @@ packages: source: hosted version: "0.2.0" sdks: - dart: ">=2.12.0 <3.0.0" - flutter: ">=1.22.0" + dart: ">=2.14.0 <3.0.0" + flutter: ">=2.5.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 61d2aa0..6cd94a3 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -13,16 +13,17 @@ description: A new Flutter project. # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html version: 1.0.0+1 +publish_to: none environment: sdk: ">=2.2.2 <3.0.0" dependencies: flutter: sdk: flutter - + # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.3 + cupertino_icons: ^1.0.4 flutter_camera_ml_vision: path: ../ diff --git a/lib/flutter_camera_ml_vision.dart b/lib/flutter_camera_ml_vision.dart index 6c9689b..f5ece39 100644 --- a/lib/flutter_camera_ml_vision.dart +++ b/lib/flutter_camera_ml_vision.dart @@ -3,22 +3,22 @@ library flutter_camera_ml_vision; import 'dart:async'; import 'dart:io'; import 'dart:typed_data'; -import 'dart:ui'; import 'package:camera/camera.dart'; import 'package:collection/collection.dart'; import 'package:device_info/device_info.dart'; -import 'package:firebase_ml_vision/firebase_ml_vision.dart'; + import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:google_ml_kit/google_ml_kit.dart'; import 'package:visibility_detector/visibility_detector.dart'; export 'package:camera/camera.dart'; part 'utils.dart'; -typedef HandleDetection = Future Function(FirebaseVisionImage image); +typedef HandleDetection = Future Function(InputImage image); typedef ErrorWidgetBuilder = Widget Function( BuildContext context, CameraError error); @@ -66,7 +66,7 @@ class CameraMlVisionState extends State> XFile? _lastImage; final _visibilityKey = UniqueKey(); CameraController? _cameraController; - ImageRotation? _rotation; + InputImageRotation? _rotation; _CameraState _cameraMlVisionState = _CameraState.loading; CameraError _cameraError = CameraError.unknown; bool _alreadyCheckingImage = false; @@ -149,7 +149,7 @@ class CameraMlVisionState extends State> CameraValue? get cameraValue => _cameraController?.value; - ImageRotation? get imageRotation => _rotation; + InputImageRotation? get imageRotation => _rotation; Future Function() get prepareForVideoRecording => _cameraController!.prepareForVideoRecording; diff --git a/lib/utils.dart b/lib/utils.dart index 571cd18..cc77716 100644 --- a/lib/utils.dart +++ b/lib/utils.dart @@ -2,7 +2,8 @@ part of 'flutter_camera_ml_vision.dart'; Future _getCamera(CameraLensDirection dir) async { final cameras = await availableCameras(); - final camera = cameras.firstWhereOrNull((camera) => camera.lensDirection == dir); + final camera = + cameras.firstWhereOrNull((camera) => camera.lensDirection == dir); return camera ?? (cameras.isEmpty ? null : cameras.first); } @@ -12,17 +13,18 @@ Uint8List _concatenatePlanes(List planes) { return allBytes.done().buffer.asUint8List(); } -FirebaseVisionImageMetadata buildMetaData( +InputImageData buildMetaData( CameraImage image, - ImageRotation rotation, + InputImageRotation rotation, ) { - return FirebaseVisionImageMetadata( - rawFormat: image.format.raw, + return InputImageData( + inputImageFormat: InputImageFormatMethods.fromRawValue(image.format.raw) ?? + InputImageFormat.NV21, size: Size(image.width.toDouble(), image.height.toDouble()), - rotation: rotation, + imageRotation: rotation, planeData: image.planes .map( - (plane) => FirebaseVisionImagePlaneMetadata( + (plane) => InputImagePlaneMetadata( bytesPerRow: plane.bytesPerRow, height: plane.height, width: plane.width, @@ -35,26 +37,26 @@ FirebaseVisionImageMetadata buildMetaData( Future _detect( CameraImage image, HandleDetection handleDetection, - ImageRotation rotation, + InputImageRotation rotation, ) async { return handleDetection( - FirebaseVisionImage.fromBytes( - _concatenatePlanes(image.planes), - buildMetaData(image, rotation), + InputImage.fromBytes( + bytes: _concatenatePlanes(image.planes), + inputImageData: buildMetaData(image, rotation), ), ); } -ImageRotation _rotationIntToImageRotation(int rotation) { +InputImageRotation _rotationIntToImageRotation(int rotation) { switch (rotation) { case 0: - return ImageRotation.rotation0; + return InputImageRotation.Rotation_0deg; case 90: - return ImageRotation.rotation90; + return InputImageRotation.Rotation_90deg; case 180: - return ImageRotation.rotation180; + return InputImageRotation.Rotation_180deg; default: assert(rotation == 270); - return ImageRotation.rotation270; + return InputImageRotation.Rotation_270deg; } } diff --git a/pubspec.lock b/pubspec.lock index ae6c6ca..63c09eb 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -21,28 +21,35 @@ packages: name: camera url: "https://pub.dartlang.org" source: hosted - version: "0.8.1" + version: "0.9.4+5" camera_platform_interface: dependency: transitive description: name: camera_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.1" + camera_web: + dependency: transitive + description: + name: camera_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.1+1" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -63,7 +70,7 @@ packages: name: cross_file url: "https://pub.dartlang.org" source: hosted - version: "0.3.1+1" + version: "0.3.2" device_info: dependency: "direct main" description: @@ -105,33 +112,33 @@ packages: name: firebase_core url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.10.6" firebase_core_platform_interface: dependency: transitive description: name: firebase_core_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "4.2.3" firebase_core_web: dependency: transitive description: name: firebase_core_web url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" - firebase_ml_vision: - dependency: "direct main" - description: - name: firebase_ml_vision - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.0+1" + version: "1.5.3" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" + flutter_plugin_android_lifecycle: + dependency: transitive + description: + name: flutter_plugin_android_lifecycle + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" flutter_test: dependency: "direct dev" description: flutter @@ -142,6 +149,13 @@ packages: description: flutter source: sdk version: "0.0.0" + google_ml_kit: + dependency: "direct main" + description: + name: google_ml_kit + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.3" js: dependency: transitive description: @@ -155,14 +169,14 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.11" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" path: dependency: transitive description: @@ -206,12 +220,12 @@ packages: source: hosted version: "2.0.0" pedantic: - dependency: "direct main" + dependency: transitive description: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.11.0" + version: "1.11.1" platform: dependency: transitive description: @@ -239,7 +253,7 @@ packages: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "3.0.1" + version: "3.0.1+1" sky_engine: dependency: transitive description: flutter @@ -251,7 +265,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -293,7 +307,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.4.3" typed_data: dependency: transitive description: @@ -307,7 +321,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" visibility_detector: dependency: "direct main" description: @@ -330,5 +344,5 @@ packages: source: hosted version: "0.2.0" sdks: - dart: ">=2.12.0 <3.0.0" - flutter: ">=1.22.0" + dart: ">=2.14.0 <3.0.0" + flutter: ">=2.5.0" diff --git a/pubspec.yaml b/pubspec.yaml index 9a193c3..6073d4d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,6 @@ name: flutter_camera_ml_vision -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... +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... version: 3.0.1 repository: https://github.com/rushio-consulting/flutter_camera_ml_vision homepage: https://github.com/rushio-consulting/flutter_camera_ml_vision @@ -8,21 +9,16 @@ environment: sdk: '>=2.12.0 <3.0.0' dependencies: + camera: ^0.9.4+5 + collection: ^1.15.0 + device_info: ^2.0.0 + firebase_core: ^1.10.5 flutter: sdk: flutter - firebase_ml_vision: ^0.12.0+1 - #git: - # url: git://github.com/algirdasmac/flutterfire - # path: packages/firebase_ml_vision - firebase_core: ^1.1.0 - visibility_detector: ^0.2.0 + google_ml_kit: ^0.7.3 path_provider: ^2.0.1 - pedantic: ^1.11.0 - device_info: ^2.0.0 - camera: ^0.8.1 - collection: ^1.15.0 + visibility_detector: ^0.2.0 dev_dependencies: flutter_test: sdk: flutter -