mlkit 0.9.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 85

mlkit

pub package

A Flutter plugin to use the Firebase ML Kit.

Only your star motivate me!

this is not official package

The flutter team now has the firebase_ml_vision package for Firebase ML Kit. Please consider trying to use firebase_ml_vision.

Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!

Features

FeatureAndroidiOS
Recognize text(on device)
Recognize text(cloud)yetyet
Detect faces(on device)
Scan barcodes(on device)
Label Images(on device)
Label Images(cloud)yetyet
Recognize landmarks(cloud)yetyet
Custom model

What features are available on device or in the cloud?

Usage

To use this plugin, add mlkit as a dependency in your pubspec.yaml file.

Getting Started

Check out the example directory for a sample app using Firebase Cloud Messaging.

Android Integration

To integrate your plugin into the Android part of your app, follow these steps:

  1. Using the Firebase Console add an Android app to your project: Follow the assistant, download the generated google-services.json file and place it inside android/app. Next, modify the android/build.gradle file and the android/app/build.gradle file to add the Google services plugin as described by the Firebase assistant.

iOS Integration

To integrate your plugin into the iOS part of your app, follow these steps:

  1. Using the Firebase Console add an iOS app to your project: Follow the assistant, download the generated GoogleService-Info.plist file, open ios/Runner.xcworkspace with Xcode, and within Xcode place the file inside ios/Runner. Don't follow the steps named "Add Firebase SDK" and "Add initialization code" in the Firebase assistant.

  2. Remove the use_frameworks! line from ios/Podfile (workaround for flutter/flutter#9694).

Dart/Flutter Integration

From your Dart code, you need to import the plugin and instantiate it:

import 'package:mlkit/mlkit.dart';

FirebaseVisionTextDetector detector = FirebaseVisionTextDetector.instance;

// Detect form file/image by path
var currentLabels = await detector.detectFromPath(_file?.path);

// Detect from binary data of a file/image
var currentLabels = await detector.detectFromBinary(_file?.readAsBytesSync());

custom model interpreter

native sample code

import 'package:mlkit/mlkit.dart';
import 'package:image/image.dart' as img;

FirebaseModelInterpreter interpreter = FirebaseModelInterpreter.instance;
FirebaseModelManager manager = FirebaseModelManager.instance;
manager.registerCloudModelSource(
        FirebaseCloudModelSource(modelName: "mobilenet_v1_224_quant"));

var imageBytes = (await rootBundle.load("assets/mountain.jpg")).buffer;
img.Image image = img.decodeJpg(imageBytes.asUint8List());
image = img.copyResize(image, 224, 224);
var results = await interpreter.run(
                    "mobilenet_v1_224_quant",
                    FirebaseModelInputOutputOptions(
                        0,
                        FirebaseModelDataType.BYTE,
                        [1, 224, 224, 3],
                        0,
                        FirebaseModelDataType.BYTE,
                        [1, 1001]),
                    imageToByteList(image));

// int model
Uint8List imageToByteList(img.Image image) {
    var _inputSize = 224;
    var convertedBytes = new Uint8List(1 * _inputSize * _inputSize * 3);
    var buffer = new ByteData.view(convertedBytes.buffer);
    int pixelIndex = 0;
    for (var i = 0; i < _inputSize; i++) {
      for (var j = 0; j < _inputSize; j++) {
        var pixel = image.getPixel(i, j);
        buffer.setUint8(pixelIndex, (pixel >> 16) & 0xFF);
        pixelIndex++;
        buffer.setUint8(pixelIndex, (pixel >> 8) & 0xFF);
        pixelIndex++;
        buffer.setUint8(pixelIndex, (pixel) & 0xFF);
        pixelIndex++;
      }
    }
    return convertedBytes;
  }

// float model
Uint8List imageToByteList(img.Image image) {
  var _inputSize = 224;
  var convertedBytes = Float32List(1 * _inputSize * _inputSize * 3);
  var buffer = Float32List.view(convertedBytes.buffer);
  int pixelIndex = 0;
  for (var i = 0; i < _inputSize; i++) {
    for (var j = 0; j < _inputSize; j++) {
      var pixel = image.getPixel(i, j);
      buffer[pixelIndex] = ((pixel >> 16) & 0xFF) / 255;
      pixelIndex += 1;
      buffer[pixelIndex] = ((pixel >> 8) & 0xFF) / 255;
      pixelIndex += 1;
      buffer[pixelIndex] = ((pixel) & 0xFF) / 255;
      pixelIndex += 1;
    }
  }
  return convertedBytes.buffer.asUint8List();
}

0.9.0

  • update android firebase dependency.
  • fix implement for custom interpreter.

0.8.3

  • static_framework = true for ios

0.8.2

  • update iOS firebase dependency. No I/F changed.

0.8.1

  • fix android rotation probelm.

0.8.0

  • update iOS firebase dependency. No I/F changed.

0.7.0

  • support custom model interpreter for both OS (cloud hosting model only).

0.6.4

  • fix android custom model interpreter.

0.6.3

  • update dependency and bug fix.

0.6.2

  • update flutter environment.

0.6.1

  • update ios textDetector implement for firebase API update.

0.6.0

  • support custom model interpreter for android (cloud hosting model only).

0.5.0

  • Added functionality to detect from binary

0.4.1

  • Added On-device Face detecting API for android.

0.4.0

  • Added On-device Face detecting API (iOS only).

0.3.0

  • Added On-device Image Labeling API.

0.2.2

  • fix package dependency for android.

0.2.1

  • fully support Scan barcodes on device.

0.2.0

  • support Scan barcodes (iOS only)

0.1.1

  • brushed up example code.

0.1.0

  • fully support Recognize text on device.

0.0.2

  • support iOS.

0.0.1

  • initial release.

example/README.md

mlkit_example

Demonstrates how to use the mlkit plugin.

Getting Started

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  mlkit: ^0.9.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:mlkit/mlkit.dart';
  
Version Uploaded Documentation Archive
0.9.0 Nov 4, 2018 Go to the documentation of mlkit 0.9.0 Download mlkit 0.9.0 archive
0.8.3 Oct 28, 2018 Go to the documentation of mlkit 0.8.3 Download mlkit 0.8.3 archive
0.8.2 Oct 28, 2018 Go to the documentation of mlkit 0.8.2 Download mlkit 0.8.2 archive
0.8.1 Oct 22, 2018 Go to the documentation of mlkit 0.8.1 Download mlkit 0.8.1 archive
0.8.0 Oct 12, 2018 Go to the documentation of mlkit 0.8.0 Download mlkit 0.8.0 archive
0.7.0 Oct 10, 2018 Go to the documentation of mlkit 0.7.0 Download mlkit 0.7.0 archive
0.6.4 Oct 8, 2018 Go to the documentation of mlkit 0.6.4 Download mlkit 0.6.4 archive
0.6.3 Sep 21, 2018 Go to the documentation of mlkit 0.6.3 Download mlkit 0.6.3 archive
0.6.2 Aug 28, 2018 Go to the documentation of mlkit 0.6.2 Download mlkit 0.6.2 archive
0.6.1 Aug 19, 2018 Go to the documentation of mlkit 0.6.1 Download mlkit 0.6.1 archive

All 22 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
87
Health:
Code health derived from static analysis. [more]
86
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
85
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Fix lib/mlkit.dart. (-14.26 points)

Analysis of lib/mlkit.dart reported 3 warnings:

line 339 col 22: The parameter 'assetFilePath' is required.

line 339 col 22: The parameter 'filePath' is required.

line 339 col 22: The parameter 'modelName' is required.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
meta ^1.1.5 1.1.6
Transitive dependencies
collection 1.14.11
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8