Skip to content

Commit

Permalink
google_mlkit_object_detection - v0.4.0 (flutter-ml#274)
Browse files Browse the repository at this point in the history
* Fix trackingId for null values.
* Update `ObjectDetectorOptions` constructor.
  • Loading branch information
fbernaly authored Jun 2, 2022
1 parent 30a1d0a commit c865020
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 62 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 2022-06-01

### Changes

---

Packages with changes:

- [`google_mlkit_object_detection` - `v0.4.0`](#google_mlkit_object_detection---v040)

---

#### `google_mlkit_object_detection` - `v0.4.0`

* Fix trackingId for null values.
* Update `ObjectDetectorOptions` constructor.

## 2022-05-18

### Changes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Google's ML Kit for Flutter is a set of [Flutter plugins](https://flutter.io/pla
- Swift 5
- ML Kit only supports 64-bit architectures (x86_64 and arm64). Check this [list](https://developer.apple.com/support/required-device-capabilities/) to see if your device has the required device capabilities.

Since ML Kit does not support 32-bit architectures (i386 and armv7), you need to exclude amrv7 architectures in Xcode in order to run `flutter build ios` or `flutter build ipa`. More info [here](https://developers.google.com/ml-kit/migration/ios).
Since ML Kit does not support 32-bit architectures (i386 and armv7), you need to exclude armv7 architectures in Xcode in order to run `flutter build ios` or `flutter build ipa`. More info [here](https://developers.google.com/ml-kit/migration/ios).

Go to Project > Runner > Building Settings > Excluded Architectures > Any SDK > armv7

Expand Down
64 changes: 32 additions & 32 deletions packages/google_ml_kit/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
PODS:
- camera (0.0.1):
- Flutter
- Firebase (8.14.0):
- Firebase/Core (= 8.14.0)
- Firebase/Core (8.14.0):
- Firebase (8.15.0):
- Firebase/Core (= 8.15.0)
- Firebase/Core (8.15.0):
- Firebase/CoreOnly
- FirebaseAnalytics (~> 8.14.0)
- Firebase/CoreOnly (8.14.0):
- FirebaseCore (= 8.14.0)
- FirebaseAnalytics (8.14.0):
- FirebaseAnalytics/AdIdSupport (= 8.14.0)
- FirebaseAnalytics (~> 8.15.0)
- Firebase/CoreOnly (8.15.0):
- FirebaseCore (= 8.15.0)
- FirebaseAnalytics (8.15.0):
- FirebaseAnalytics/AdIdSupport (= 8.15.0)
- FirebaseCore (~> 8.0)
- FirebaseInstallations (~> 8.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.7)
- GoogleUtilities/MethodSwizzler (~> 7.7)
- GoogleUtilities/Network (~> 7.7)
- "GoogleUtilities/NSData+zlib (~> 7.7)"
- nanopb (~> 2.30908.0)
- FirebaseAnalytics/AdIdSupport (8.14.0):
- FirebaseAnalytics/AdIdSupport (8.15.0):
- FirebaseCore (~> 8.0)
- FirebaseInstallations (~> 8.0)
- GoogleAppMeasurement (= 8.14.0)
- GoogleAppMeasurement (= 8.15.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.7)
- GoogleUtilities/MethodSwizzler (~> 7.7)
- GoogleUtilities/Network (~> 7.7)
- "GoogleUtilities/NSData+zlib (~> 7.7)"
- nanopb (~> 2.30908.0)
- FirebaseCore (8.14.0):
- FirebaseCore (8.15.0):
- FirebaseCoreDiagnostics (~> 8.0)
- GoogleUtilities/Environment (~> 7.7)
- GoogleUtilities/Logger (~> 7.7)
- FirebaseCoreDiagnostics (8.14.0):
- FirebaseCoreDiagnostics (8.15.0):
- GoogleDataTransport (~> 9.1)
- GoogleUtilities/Environment (~> 7.7)
- GoogleUtilities/Logger (~> 7.7)
- nanopb (~> 2.30908.0)
- FirebaseInstallations (8.14.0):
- FirebaseInstallations (8.15.0):
- FirebaseCore (~> 8.0)
- GoogleUtilities/Environment (~> 7.7)
- GoogleUtilities/UserDefaults (~> 7.7)
Expand Down Expand Up @@ -101,29 +101,29 @@ PODS:
- Flutter
- google_mlkit_commons
- GoogleMLKit/Translate (~> 2.6.0)
- GoogleAppMeasurement (8.14.0):
- GoogleAppMeasurement/AdIdSupport (= 8.14.0)
- GoogleAppMeasurement (8.15.0):
- GoogleAppMeasurement/AdIdSupport (= 8.15.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.7)
- GoogleUtilities/MethodSwizzler (~> 7.7)
- GoogleUtilities/Network (~> 7.7)
- "GoogleUtilities/NSData+zlib (~> 7.7)"
- nanopb (~> 2.30908.0)
- GoogleAppMeasurement/AdIdSupport (8.14.0):
- GoogleAppMeasurement/WithoutAdIdSupport (= 8.14.0)
- GoogleAppMeasurement/AdIdSupport (8.15.0):
- GoogleAppMeasurement/WithoutAdIdSupport (= 8.15.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.7)
- GoogleUtilities/MethodSwizzler (~> 7.7)
- GoogleUtilities/Network (~> 7.7)
- "GoogleUtilities/NSData+zlib (~> 7.7)"
- nanopb (~> 2.30908.0)
- GoogleAppMeasurement/WithoutAdIdSupport (8.14.0):
- GoogleAppMeasurement/WithoutAdIdSupport (8.15.0):
- GoogleUtilities/AppDelegateSwizzler (~> 7.7)
- GoogleUtilities/MethodSwizzler (~> 7.7)
- GoogleUtilities/Network (~> 7.7)
- "GoogleUtilities/NSData+zlib (~> 7.7)"
- nanopb (~> 2.30908.0)
- GoogleDataTransport (9.1.2):
- GoogleUtilities/Environment (~> 7.2)
- nanopb (~> 2.30908.0)
- GoogleDataTransport (9.1.4):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30910.0, >= 2.30908.0)
- PromisesObjC (< 3.0, >= 1.2)
- GoogleMLKit/BarcodeScanning (2.6.0):
- GoogleMLKit/MLKitCore
Expand Down Expand Up @@ -222,7 +222,7 @@ PODS:
- GoogleUtilities/Logger
- GoogleUtilitiesComponents (1.1.0):
- GoogleUtilities/Logger
- GTMSessionFetcher/Core (1.7.1)
- GTMSessionFetcher/Core (1.7.2)
- image_picker_ios (0.0.1):
- Flutter
- MLImage (1.0.0-beta2)
Expand Down Expand Up @@ -358,7 +358,7 @@ PODS:
- path_provider_ios (0.0.1):
- Flutter
- PromisesObjC (2.1.0)
- Protobuf (3.20.0)
- Protobuf (3.21.1)
- SSZipArchive (2.4.3)

DEPENDENCIES:
Expand Down Expand Up @@ -470,11 +470,11 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
camera: 9993f92f2c793e87b65e35f3a23c70582afb05b1
Firebase: 7e8fe528c161b9271d365217a74c16aaf834578e
FirebaseAnalytics: 2fc3876e2eb347673ad2f35e249ae7b15d6c88f5
FirebaseCore: b84a44ee7ba999e0f9f76d198a9c7f60a797b848
FirebaseCoreDiagnostics: fd0c8490f34287229c1d6c103d3a55f81ec85712
FirebaseInstallations: 7d1d967a307c12f1aadd76844fc321cef699b1ce
Firebase: 5f8193dff4b5b7c5d5ef72ae54bb76c08e2b841d
FirebaseAnalytics: 7761cbadb00a717d8d0939363eb46041526474fa
FirebaseCore: 5743c5785c074a794d35f2fff7ecc254a91e08b1
FirebaseCoreDiagnostics: 92e07a649aeb66352b319d43bdd2ee3942af84cb
FirebaseInstallations: 40bd9054049b2eae9a2c38ef1c3dd213df3605cd
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
google_mlkit_barcode_scanning: 56e88993b6c915ce7134f9d77cb5b2de2fca8cfa
google_mlkit_commons: e9070f57232c3a3e4bd42fdfa621bb1f4bb3e709
Expand All @@ -489,13 +489,13 @@ SPEC CHECKSUMS:
google_mlkit_smart_reply: fc9ba6a5c97e491c9b326ef9313768cfc30bbe6b
google_mlkit_text_recognition: 99cf85a1eb8ff9f2918c959bd8c907ba4489b6ec
google_mlkit_translation: 3c94c6d77999331af627f2b4bd29bbbb8b2d2f42
GoogleAppMeasurement: 71156240babd3cc6ced03e0d54816f01a880c730
GoogleDataTransport: 629c20a4d363167143f30ea78320d5a7eb8bd940
GoogleAppMeasurement: 4c19f031220c72464d460c9daa1fb5d1acce958e
GoogleDataTransport: 5fffe35792f8b96ec8d6775f5eccd83c998d5a3b
GoogleMLKit: 755661c46990a85e42278015f26400286d98ad95
GoogleToolboxForMac: 8bef7c7c5cf7291c687cf5354f39f9db6399ad34
GoogleUtilities: e0913149f6b0625b553d70dae12b49fc62914fd1
GoogleUtilitiesComponents: 679b2c881db3b615a2777504623df6122dd20afe
GTMSessionFetcher: 4577a4cc914a5a07c40a8a0ad0acc22080418c2d
GTMSessionFetcher: 5595ec75acf5be50814f81e9189490412bad82ba
image_picker_ios: b786a5dcf033a8336a657191401bfdf12017dabb
MLImage: a454f9f8ecfd537783a12f9488f5be1a68820829
MLKitBarcodeScanning: b8257854f6afc1c8443d61ec6b98c28b35625df6
Expand Down Expand Up @@ -532,7 +532,7 @@ SPEC CHECKSUMS:
nanopb: a0ba3315591a9ae0a16a309ee504766e90db0c96
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
PromisesObjC: 99b6f43f9e1044bd87a95a60beff28c2c44ddb72
Protobuf: 66e2f3b26a35e4cc379831f4ced538274ee4b923
Protobuf: 9e88c1e667d75aa2491d211f26ccddde4e8ad4cf
SSZipArchive: fe6a26b2a54d5a0890f2567b5cc6de5caa600aef

PODFILE CHECKSUM: fe8b2255afcb9d09e6120de35c0815e05a905905
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ class CameraView extends StatefulWidget {
required this.customPaint,
this.text,
required this.onImage,
this.onScreenModeChanged,
this.initialDirection = CameraLensDirection.back})
: super(key: key);

final String title;
final CustomPaint? customPaint;
final String? text;
final Function(InputImage inputImage) onImage;
final Function(ScreenMode mode)? onScreenModeChanged;
final CameraLensDirection initialDirection;

@override
Expand Down Expand Up @@ -246,6 +248,9 @@ class _CameraViewState extends State<CameraView> {
_mode = ScreenMode.liveFeed;
_startLiveFeed();
}
if (widget.onScreenModeChanged != null) {
widget.onScreenModeChanged!(_mode);
}
setState(() {});
}

Expand Down Expand Up @@ -312,12 +317,12 @@ class _CameraViewState extends State<CameraView> {

final camera = cameras[_cameraIndex];
final imageRotation =
InputImageRotationValue.fromRawValue(camera.sensorOrientation) ??
InputImageRotation.rotation0deg;
InputImageRotationValue.fromRawValue(camera.sensorOrientation);
if (imageRotation == null) return;

final inputImageFormat =
InputImageFormatValue.fromRawValue(image.format.raw) ??
InputImageFormat.nv21;
InputImageFormatValue.fromRawValue(image.format.raw);
if (inputImageFormat == null) return;

final planeData = image.planes.map(
(Plane plane) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class _ObjectDetectorView extends State<ObjectDetectorView> {
void initState() {
super.initState();

_initializeDetector();
_initializeDetector(DetectionMode.stream);
}

@override
Expand All @@ -45,21 +45,39 @@ class _ObjectDetectorView extends State<ObjectDetectorView> {
onImage: (inputImage) {
processImage(inputImage);
},
onScreenModeChanged: _onScreenModeChanged,
initialDirection: CameraLensDirection.back,
);
}

void _initializeDetector() async {
void _onScreenModeChanged(ScreenMode mode) {
switch (mode) {
case ScreenMode.gallery:
_initializeDetector(DetectionMode.single);
return;

case ScreenMode.liveFeed:
_initializeDetector(DetectionMode.stream);
return;
}
}

void _initializeDetector(DetectionMode mode) async {
print('Set detector in mode: $mode');

// uncomment next lines if you want to use the default model
// final options =
// ObjectDetectorOptions(classifyObjects: true, multipleObjects: true);
// final options = ObjectDetectorOptions(
// mode: mode,
// classifyObjects: true,
// multipleObjects: true);
// _objectDetector = ObjectDetector(options: options);

// uncomment next lines if you want to use a local model
// make sure to add tflite model to assets/ml
final path = 'assets/ml/object_labeler.tflite';
final modelPath = await _getModel(path);
final options = LocalObjectDetectorOptions(
mode: mode,
modelPath: modelPath,
classifyObjects: true,
multipleObjects: true,
Expand All @@ -73,6 +91,7 @@ class _ObjectDetectorView extends State<ObjectDetectorView> {
// await FirebaseObjectDetectorModelManager().downloadModel(modelName);
// print('Downloaded: $response');
// final options = FirebaseObjectDetectorOptions(
// mode: mode,
// modelName: modelName,
// classifyObjects: true,
// multipleObjects: true,
Expand Down
7 changes: 3 additions & 4 deletions packages/google_mlkit_commons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ From [CameraImage](https://pub.dev/documentation/camera/latest/camera/CameraImag
import 'package:google_mlkit_commons/google_mlkit_commons.dart';
final camera; // your camera instance
final WriteBuffer allBytes = WriteBuffer();
for (final Plane plane in cameraImage.planes) {
allBytes.putUint8List(plane.bytes);
Expand All @@ -48,12 +49,10 @@ final bytes = allBytes.done().buffer.asUint8List();
final Size imageSize = Size(cameraImage.width.toDouble(), cameraImage.height.toDouble());
final InputImageRotation imageRotation =
InputImageRotationValue.fromRawValue(camera.sensorOrientation) ??
InputImageRotation.rotation0deg;
InputImageRotationValue.fromRawValue(camera.sensorOrientation);
final InputImageFormat inputImageFormat =
InputImageFormatValue.fromRawValue(cameraImage.format.raw) ??
InputImageFormat.nv21;
InputImageFormatValue.fromRawValue(cameraImage.format.raw);
final planeData = cameraImage.planes.map(
(Plane plane) {
Expand Down
5 changes: 5 additions & 0 deletions packages/google_mlkit_object_detection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.4.0

* Fix trackingId for null values.
* Update `ObjectDetectorOptions` constructor.

## 0.3.0

* Allow multiple instances in native layer.
Expand Down
15 changes: 14 additions & 1 deletion packages/google_mlkit_object_detection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@ final InputImage inputImage;
#### Create an instance of `ObjectDetector`

```dart
final objectDetector = ObjectDetector(options: CustomObjectDetectorOptions or ObjectDetectorOptions)
// Use DetectionMode.stream when processing camera feed.
// Use DetectionMode.single when processing a single image.
final mode = DetectionMode.stream or DetectionMode.single;
// Options to configure the detector while using with base model.
final options = ObjectDetectorOptions(...);
// Options to configure the detector while using a local custom model.
final options = LocalObjectDetectorOptions(...);
// Options to configure the detector while using a Firebase model.
final options = FirebaseObjectDetectorOptions(...);
final objectDetector = ObjectDetector(options: options);
```

#### Process image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,18 @@ - (void)handleDetection:(FlutterMethodCall *)call result:(FlutterResult)result {
@"confidence" : @(label.confidence),
}];
}
NSDictionary *data = @{
NSMutableDictionary *data = [NSMutableDictionary dictionaryWithDictionary:@{
@"rect" : @{
@"left" : @(object.frame.origin.x),
@"top" : @(object.frame.origin.y),
@"right" : @(object.frame.origin.x + object.frame.size.width),
@"bottom" : @(object.frame.origin.y + object.frame.size.height)
},
@"labels" : labels,
@"trackingId" : object.trackingID,

};
@"labels" : labels
}];
if (object.trackingID != NULL) {
data[@"trackingId"] = object.trackingID;
}
[objectsData addObject:data];
}

Expand Down
Loading

0 comments on commit c865020

Please sign in to comment.