flutter_camera_ml_vision 2.2.0

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

Flutter Camera Ml Vision #

pub package

A Flutter package for iOS and Android to show a preview of the camera and detect things with Firebase ML Vision.

Installation #

First, add `flutter_camera_ml_vision as a dependency.

...
dependencies:
  flutter:
    sdk: flutter
  flutter_camera_ml_vision: ^1.0.0
...

Configure Firebase #

You must also configure Firebase for each platform project: Android and iOS (see the example folder or https://codelabs.developers.google.com/codelabs/flutter-firebase/#4 for step by step details).

iOS #

Add two rows to the ios/Runner/Info.plist:

  • one with the key Privacy - Camera Usage Description and a usage description.
  • and one with the key Privacy - Microphone Usage Description and a usage description. Or in text format add the key:
<key>NSCameraUsageDescription</key>
<string>Can I use the camera please?</string>
<key>NSMicrophoneUsageDescription</key>
<string>Can I use the mic please?</string>

If you're using one of the on-device APIs, include the corresponding ML Kit library model in your Podfile. Then run pod update in a terminal within the same directory as your Podfile.

pod 'Firebase/MLVisionBarcodeModel'
pod 'Firebase/MLVisionFaceModel'
pod 'Firebase/MLVisionLabelModel'
pod 'Firebase/MLVisionTextModel'

Android #

Change the minimum Android sdk version to 21 (or higher) in your android/app/build.gradle file.

minSdkVersion 21

ps: This is due to the dependency on the camera plugin.

If you're using the on-device LabelDetector, include the latest matching ML Kit: Image Labeling dependency in your app-level build.gradle file.

android {
    dependencies {
        // ...

        api 'com.google.firebase:firebase-ml-vision-image-label-model:17.0.2'
    }
}

If you receive compilation errors, try an earlier version of ML Kit: Image Labeling.

Optional but recommended: If you use the on-device API, configure your app to automatically download the ML model to the device after your app is installed from the Play Store. To do so, add the following declaration to your app's AndroidManifest.xml file:

<application ...>
  ...
  <meta-data
    android:name="com.google.firebase.ml.vision.DEPENDENCIES"
    android:value="ocr" />
  <!-- To use multiple models: android:value="ocr,label,barcode,face" -->
</application>

Usage #

1. Example with Barcode #

CameraMlVision<List<Barcode>>(
  detector: FirebaseVision.instance.barcodeDetector().detectInImage,
  onResult: (List<Barcode> barcodes) {
    if (!mounted || resultSent) {
      return;
    }
    resultSent = true;
    Navigator.of(context).pop<Barcode>(barcodes.first);
  },
)

CameraMlVision is a widget that show the preview of the camera. It take a detector as parameter here we pass the detectInImage method of the BarcodeDetector object. The detector parameter can take all the different FirebaseVision Detector. Here is a list :

FirebaseVision.instance.barcodeDetector().detectInImage
FirebaseVision.instance.cloudLabelDetector().detectInImage
FirebaseVision.instance.faceDetector().processImage
FirebaseVision.instance.labelDetector().detectInImage
FirebaseVision.instance.textRecognizer().processImage

Then when something is detected the onResult callback is called with the data in the parameter of the function.

Exposed functionality from CameraController #

We expose some functionality from the CameraController class here a a list of these :

  • value
  • prepareForVideoRecording
  • startVideoRecording
  • stopVideoRecording
  • takePicture

Getting Started #

See the example directory for a complete sample app.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Technical Support #

For any technical support, don't hesitate to contact us. Find more information in our website

For now, all the issues with the label support mean that they come out of the scope of the following project. So you can contact us as a support.

[2.2.0] - 16/06/2019

  • disable audio (#43)
  • let user define camera resolution (#45)

[2.1.0] - 16/05/2019

expose more function from camera controller

  • prepareForVideoRecording
  • startVideoRecording
  • stopVideoRecording
  • takePicture

[2.0.1] - 5/05/2019

  • fix a crash when poping a route with the camera preview

[2.0.0] - 2/05/2019

  • We now forward the result from firebase_ml_vision for onResult

[1.4.0] - 24/04/2019

  • add cameraLensDirection parameter (this default to back)

[1.3.0] - 17/04/2019

  • add overlayBuilder parameter

[1.2.0] - 12/04/2019

  • fix crash above android api 21.
  • fix pause when a new route is pushed.

[1.1.0] - 11/04/2019

  • Allow usage under android api 21.
  • Add error type on error builder.

[1.0.0] - 10/04/2019

  • Initial release.

example/README.md

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';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  List<String> data = [];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          RaisedButton(
            child: Text('Scan product'),
            onPressed: () async {
              final barcode = await Navigator.of(context).push<Barcode>(
                MaterialPageRoute(
                  builder: (c) {
                    return ScanPage();
                  },
                ),
              );
              if (barcode == null) {
                return;
              }

              setState(() {
                data.add(barcode.displayValue);
              });
            },
          ),
          Expanded(
            child: ListView(
              children: data.map((d) => Text(d)).toList(),
            ),
          ),
        ],
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

class ScanPage extends StatefulWidget {
  @override
  _ScanPageState createState() => _ScanPageState();
}

class _ScanPageState extends State<ScanPage> {
  bool resultSent = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: SizedBox(
          width: MediaQuery.of(context).size.width,
          child: CameraMlVision<List<Barcode>>(
            detector: FirebaseVision.instance.barcodeDetector().detectInImage,
            onResult: (List<Barcode> barcodes) {
              if (!mounted || resultSent) {
                return;
              }
              resultSent = true;
              Navigator.of(context).pop<Barcode>(barcodes.first);
            },
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_camera_ml_vision: ^2.2.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_camera_ml_vision/flutter_camera_ml_vision.dart';
  
Version Uploaded Documentation Archive
2.2.0 Jun 13, 2019 Go to the documentation of flutter_camera_ml_vision 2.2.0 Download flutter_camera_ml_vision 2.2.0 archive
2.1.0 May 16, 2019 Go to the documentation of flutter_camera_ml_vision 2.1.0 Download flutter_camera_ml_vision 2.1.0 archive
2.0.1 May 5, 2019 Go to the documentation of flutter_camera_ml_vision 2.0.1 Download flutter_camera_ml_vision 2.0.1 archive
2.0.0 May 2, 2019 Go to the documentation of flutter_camera_ml_vision 2.0.0 Download flutter_camera_ml_vision 2.0.0 archive
1.5.1 May 2, 2019 Go to the documentation of flutter_camera_ml_vision 1.5.1 Download flutter_camera_ml_vision 1.5.1 archive
1.5.0 Apr 27, 2019 Go to the documentation of flutter_camera_ml_vision 1.5.0 Download flutter_camera_ml_vision 1.5.0 archive
1.4.0 Apr 24, 2019 Go to the documentation of flutter_camera_ml_vision 1.4.0 Download flutter_camera_ml_vision 1.4.0 archive
1.2.0 Apr 12, 2019 Go to the documentation of flutter_camera_ml_vision 1.2.0 Download flutter_camera_ml_vision 1.2.0 archive
1.1.0 Apr 11, 2019 Go to the documentation of flutter_camera_ml_vision 1.1.0 Download flutter_camera_ml_vision 1.1.0 archive
1.0.0+1 Apr 10, 2019 Go to the documentation of flutter_camera_ml_vision 1.0.0+1 Download flutter_camera_ml_vision 1.0.0+1 archive

All 11 versions...

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

We analyzed this package on Jun 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.2
  • pana: 0.12.18
  • Flutter: 1.5.4-hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/flutter_camera_ml_vision.dart. (-0.50 points)

Analysis of lib/flutter_camera_ml_vision.dart reported 1 hint:

line 92 col 7: Await only futures.

Maintenance issues and suggestions

Support latest dependencies. (-15 points)

The version constraint in pubspec.yaml does not support the latest published versions for 2 dependencies (1 direct: firebase_ml_vision).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
camera ^0.5.2+1 0.5.2+1
device_info ^0.4.0+1 0.4.0+2
firebase_ml_vision ^0.8.0 0.8.0+3 0.9.0
flutter 0.0.0
path_provider ^1.1.0 1.1.0
pedantic ^1.4.0 1.7.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test