flutter_mobile_vision 0.1.1

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

flutter_mobile_vision

Codacy Badge pub package

Flutter implementation for Google Mobile Vision.

Based on Google Mobile Vision.

Android Samples -=- iOS Samples

Liked? ⭐ Star the repo to support the project!

Features

  • [x] Android

    • [x] Barcode Scan
      • [x] Simple scan.
      • [x] Toggle torch.
      • [x] Toggle auto focus.
      • [x] Specify types of barcodes that will be read.
      • [x] Tap to capture.
      • [x] Select barcode type to be scanned.
      • [x] Scan multiple barcodes.
      • [x] Barcode coordinates.
      • [x] Show barcode text.
      • [x] Standard code.
    • [x] Recognize Text
      • [x] Simple OCR.
      • [x] Toggle torch.
      • [x] Toggle auto focus.
      • [x] Multiple recognition.
      • [x] Text language.
      • [x] Text coordinates.
      • [x] Hide recognized text.
      • [x] Standard code.
    • [x] Detect Faces
      • [x] Simple detection.
      • [x] Toggle torch.
      • [x] Toggle auto focus.
      • [x] Multiple detection.
      • [x] Face coordinates.
      • [x] Hide detection information.
      • [x] Standard code.
    • [x] Generalization of capture activities.
    • [x] Choose between back and front camera.
    • [x] Control camera FPS.
  • [ ] iOS

    • [ ] Barcode Scan
      • [ ] Future Tasks
    • [ ] Recognize Text
      • [ ] Future Tasks
    • [ ] Detect Faces
      • [ ] Future Tasks

Your feature isn't listed? Open a issue right now!

Screenshots

<img src="docs/flutter_01.png" height="300em"/> <img src="docs/flutter_02.png" height="300em"/> <img src="docs/flutter_03.png" height="300em"/> <img src="docs/flutter_04.png" height="300em"/> <img src="docs/flutter_05.png" height="300em"/> <img src="docs/flutter_06.png" height="300em"/> <img src="docs/flutter_07.png" height="300em"/> <img src="docs/flutter_08.png" height="300em"/>

Usage

Example

To use this plugin :

  • add the dependency to your pubspec.yaml file:
  dependencies:
    flutter:
      sdk: flutter
    flutter_mobile_vision: ^0.1.1

Barcode

//...
List<Barcode> barcodes = [];
try {
  barcodes = await FlutterMobileVision.scan(
    flash: _torchBarcode,
    autoFocus: _autoFocusBarcode,
    formats: _onlyFormatBarcode,
    multiple: _multipleBarcode,
    waitTap: _waitTapBarcode,
    showText: _showTextBarcode,
    camera: _cameraBarcode,
    fps: 15.0,
  );
} on Exception {
  barcodes.add(new Barcode('Failed to get barcode.'));
}
//...

Android

For Android, you must do the following before you can use the plugin:

  • Add the camera permission to your AndroidManifest.xml

    <uses-feature android:name="android.hardware.camera" />

    <uses-permission android:name="android.permission.CAMERA" />

  • Add the Barcode activity to your AndroidManifest.xml

    <activity android:name="io.github.edufolly.fluttermobilevision.barcode.BarcodeCaptureActivity" />

iOS

If you can help, the community thanks. Your fork is needed. 😉


OCR

//...
List<OcrText> texts = [];
try {
  texts = await FlutterMobileVision.read(
    flash: _torchOcr,
    autoFocus: _autoFocusOcr,
    multiple: _multipleOcr,
    showText: _showTextOcr,
    camera: _cameraOcr,
    fps: 2.0,
  );
} on Exception {
  texts.add(new OcrText('Failed to recognize text.'));
}
//...

Android

For Android, you must do the following before you can use the plugin:

  • Add the camera permission to your AndroidManifest.xml

    <uses-feature android:name="android.hardware.camera" />

    <uses-permission android:name="android.permission.CAMERA" />

  • Add the OCR activity to your AndroidManifest.xml

    <activity android:name="io.github.edufolly.fluttermobilevision.ocr.OcrCaptureActivity" />

iOS

If you can help, the community thanks. Your fork is needed. 😉


Face Detection

//...
List<Face> faces = [];
try {
  faces = await FlutterMobileVision.face(
    flash: _torchFace,
    autoFocus: _autoFocusFace,
    multiple: _multipleFace,
    showText: _showTextFace,
    camera: _cameraFace,
    fps: 15.0,
  );
} on Exception {
  faces.add(new Face(-1));
}
//...

Android

For Android, you must do the following before you can use the plugin:

  • Add the camera permission to your AndroidManifest.xml

    <uses-feature android:name="android.hardware.camera" />

    <uses-permission android:name="android.permission.CAMERA" />

  • Add the Face Detection activity to your AndroidManifest.xml

    <activity android:name="io.github.edufolly.fluttermobilevision.face.FaceCaptureActivity" />

iOS

If you can help, the community thanks. Your fork is needed. 😉

[0.1.1] - 2018-07-08

  • Bug fixed - Crash when the permission is not granted on Android #7

[0.1.0] - 2018-05-06

  • Production mode on.

[0.0.4] - 2018-05-04

  • Face Detection.

[0.0.3] - 2018-05-02

  • Text Recognition.
  • Improvements.

[0.0.2] - 2018-04-23

  • Multiple Scans.
  • And a lot of new features.

[0.0.1] - 2018-04-22

  • Basic test functions.
  • Only Scan Barcodes.
  • Only Android support.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_mobile_vision/flutter_mobile_vision.dart';
import 'package:flutter_mobile_vision_example/barcode_detail.dart';
import 'package:flutter_mobile_vision_example/face_detail.dart';
import 'package:flutter_mobile_vision_example/ocr_text_detail.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int _cameraBarcode = FlutterMobileVision.CAMERA_BACK;
  int _onlyFormatBarcode = Barcode.ALL_FORMATS;
  bool _autoFocusBarcode = true;
  bool _torchBarcode = false;
  bool _multipleBarcode = false;
  bool _waitTapBarcode = false;
  bool _showTextBarcode = false;
  List<Barcode> _barcodes = [];

  int _cameraOcr = FlutterMobileVision.CAMERA_BACK;
  bool _autoFocusOcr = true;
  bool _torchOcr = false;
  bool _multipleOcr = false;
  bool _showTextOcr = true;
  List<OcrText> _textsOcr = [];

  int _cameraFace = FlutterMobileVision.CAMERA_FRONT;
  bool _autoFocusFace = true;
  bool _torchFace = false;
  bool _multipleFace = true;
  bool _showTextFace = true;
  List<Face> _faces = [];

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      theme: new ThemeData(
        primarySwatch: Colors.lime,
        buttonColor: Colors.lime,
      ),
      home: new DefaultTabController(
        length: 3,
        child: new Scaffold(
          appBar: new AppBar(
            bottom: new TabBar(
              indicatorColor: Colors.black54,
              tabs: [
                new Tab(text: 'Barcode'),
                new Tab(text: 'OCR'),
                new Tab(text: 'Face')
              ],
            ),
            title: new Text('Flutter Mobile Vision'),
          ),
          body: new TabBarView(children: [
            _getScanScreen(context),
            _getOcrScreen(context),
            _getFaceScreen(context),
          ]),
        ),
      ),
    );
  }

  ///
  /// Scan formats
  ///
  List<DropdownMenuItem<int>> _getFormats() {
    List<DropdownMenuItem<int>> formatItems = [];

    Barcode.mapFormat.forEach((key, value) {
      formatItems.add(new DropdownMenuItem(
        child: new Text(value),
        value: key,
      ));
    });

    return formatItems;
  }

  ///
  /// Camera list
  ///
  List<DropdownMenuItem<int>> _getCameras() {
    List<DropdownMenuItem<int>> formatItems = [];

    formatItems.add(new DropdownMenuItem(
      child: new Text('BACK'),
      value: FlutterMobileVision.CAMERA_BACK,
    ));

    formatItems.add(new DropdownMenuItem(
      child: new Text('FRONT'),
      value: FlutterMobileVision.CAMERA_FRONT,
    ));

    return formatItems;
  }

  ///
  /// Scan Screen
  ///
  Widget _getScanScreen(BuildContext context) {
    List<Widget> items = [];

    items.add(new Padding(
      padding: const EdgeInsets.only(
        top: 8.0,
        left: 18.0,
        right: 18.0,
      ),
      child: const Text('Camera:'),
    ));

    items.add(new Padding(
      padding: const EdgeInsets.only(
        left: 18.0,
        right: 18.0,
      ),
      child: new DropdownButton(
        items: _getCameras(),
        onChanged: (value) => setState(
              () => _cameraBarcode = value,
            ),
        value: _cameraBarcode,
      ),
    ));

    items.add(new Padding(
      padding: const EdgeInsets.only(
        top: 8.0,
        left: 18.0,
        right: 18.0,
      ),
      child: const Text('Scan format only:'),
    ));

    items.add(new Padding(
      padding: const EdgeInsets.only(
        left: 18.0,
        right: 18.0,
      ),
      child: new DropdownButton(
        items: _getFormats(),
        onChanged: (value) => setState(
              () => _onlyFormatBarcode = value,
            ),
        value: _onlyFormatBarcode,
      ),
    ));

    items.add(new SwitchListTile(
      title: const Text('Auto focus:'),
      value: _autoFocusBarcode,
      onChanged: (value) => setState(() => _autoFocusBarcode = value),
    ));

    items.add(new SwitchListTile(
      title: const Text('Torch:'),
      value: _torchBarcode,
      onChanged: (value) => setState(() => _torchBarcode = value),
    ));

    items.add(new SwitchListTile(
      title: const Text('Multiple Scan:'),
      value: _multipleBarcode,
      onChanged: (value) => setState(() {
            _multipleBarcode = value;
            if (value) _waitTapBarcode = true;
          }),
    ));

    items.add(new SwitchListTile(
      title: const Text('Wait a tap to capture:'),
      value: _waitTapBarcode,
      onChanged: (value) => setState(() {
            _waitTapBarcode = value;
            if (!value) _multipleBarcode = false;
          }),
    ));

    items.add(new SwitchListTile(
      title: const Text('Show text:'),
      value: _showTextBarcode,
      onChanged: (value) => setState(() => _showTextBarcode = value),
    ));

    items.add(
      new Padding(
        padding: const EdgeInsets.only(
          left: 18.0,
          right: 18.0,
          bottom: 12.0,
        ),
        child: new RaisedButton(
          onPressed: _scan,
          child: new Text('SCAN!'),
        ),
      ),
    );

    items.addAll(
      ListTile.divideTiles(
        context: context,
        tiles: _barcodes
            .map(
              (barcode) => new BarcodeWidget(barcode),
            )
            .toList(),
      ),
    );

    return new ListView(
      padding: const EdgeInsets.only(
        top: 12.0,
      ),
      children: items,
    );
  }

  ///
  /// Scan Method
  ///
  Future<Null> _scan() async {
    List<Barcode> barcodes = [];
    try {
      barcodes = await FlutterMobileVision.scan(
        flash: _torchBarcode,
        autoFocus: _autoFocusBarcode,
        formats: _onlyFormatBarcode,
        multiple: _multipleBarcode,
        waitTap: _waitTapBarcode,
        showText: _showTextBarcode,
        camera: _cameraBarcode,
        fps: 15.0,
      );
    } on Exception {
      barcodes.add(new Barcode('Failed to get barcode.'));
    }

    if (!mounted) return;

    setState(() => _barcodes = barcodes);
  }

  ///
  /// OCR Screen
  ///
  Widget _getOcrScreen(BuildContext context) {
    List<Widget> items = [];

    items.add(new Padding(
      padding: const EdgeInsets.only(
        top: 8.0,
        left: 18.0,
        right: 18.0,
      ),
      child: const Text('Camera:'),
    ));

    items.add(new Padding(
      padding: const EdgeInsets.only(
        left: 18.0,
        right: 18.0,
      ),
      child: new DropdownButton(
        items: _getCameras(),
        onChanged: (value) => setState(
              () => _cameraOcr = value,
            ),
        value: _cameraOcr,
      ),
    ));

    items.add(new SwitchListTile(
      title: const Text('Auto focus:'),
      value: _autoFocusOcr,
      onChanged: (value) => setState(() => _autoFocusOcr = value),
    ));

    items.add(new SwitchListTile(
      title: const Text('Torch:'),
      value: _torchOcr,
      onChanged: (value) => setState(() => _torchOcr = value),
    ));

    items.add(new SwitchListTile(
      title: const Text('Multiple:'),
      value: _multipleOcr,
      onChanged: (value) => setState(() => _multipleOcr = value),
    ));

    items.add(new SwitchListTile(
      title: const Text('Show text:'),
      value: _showTextOcr,
      onChanged: (value) => setState(() => _showTextOcr = value),
    ));

    items.add(
      new Padding(
        padding: const EdgeInsets.only(
          left: 18.0,
          right: 18.0,
          bottom: 12.0,
        ),
        child: new RaisedButton(
          onPressed: _read,
          child: new Text('READ!'),
        ),
      ),
    );

    items.addAll(
      ListTile.divideTiles(
        context: context,
        tiles: _textsOcr
            .map(
              (ocrText) => new OcrTextWidget(ocrText),
            )
            .toList(),
      ),
    );

    return new ListView(
      padding: const EdgeInsets.only(
        top: 12.0,
      ),
      children: items,
    );
  }

  ///
  /// OCR Method
  ///
  Future<Null> _read() async {
    List<OcrText> texts = [];
    try {
      texts = await FlutterMobileVision.read(
        flash: _torchOcr,
        autoFocus: _autoFocusOcr,
        multiple: _multipleOcr,
        showText: _showTextOcr,
        camera: _cameraOcr,
        fps: 2.0,
      );
    } on Exception {
      texts.add(new OcrText('Failed to recognize text.'));
    }

    if (!mounted) return;

    setState(() => _textsOcr = texts);
  }

  ///
  /// Face Screen
  ///
  Widget _getFaceScreen(BuildContext context) {
    List<Widget> items = [];

    items.add(new Padding(
      padding: const EdgeInsets.only(
        top: 8.0,
        left: 18.0,
        right: 18.0,
      ),
      child: const Text('Camera:'),
    ));

    items.add(new Padding(
      padding: const EdgeInsets.only(
        left: 18.0,
        right: 18.0,
      ),
      child: new DropdownButton(
        items: _getCameras(),
        onChanged: (value) => setState(
              () => _cameraFace = value,
            ),
        value: _cameraFace,
      ),
    ));

    items.add(new SwitchListTile(
      title: const Text('Auto focus:'),
      value: _autoFocusFace,
      onChanged: (value) => setState(() => _autoFocusFace = value),
    ));

    items.add(new SwitchListTile(
      title: const Text('Torch:'),
      value: _torchFace,
      onChanged: (value) => setState(() => _torchFace = value),
    ));

    items.add(new SwitchListTile(
      title: const Text('Multiple:'),
      value: _multipleFace,
      onChanged: (value) => setState(() => _multipleFace = value),
    ));

    items.add(new SwitchListTile(
      title: const Text('Show text:'),
      value: _showTextFace,
      onChanged: (value) => setState(() => _showTextFace = value),
    ));

    items.add(
      new Padding(
        padding: const EdgeInsets.only(
          left: 18.0,
          right: 18.0,
          bottom: 12.0,
        ),
        child: new RaisedButton(
          onPressed: _face,
          child: new Text('DETECT!'),
        ),
      ),
    );

    items.addAll(
      ListTile.divideTiles(
        context: context,
        tiles: _faces
            .map(
              (face) => new FaceWidget(face),
            )
            .toList(),
      ),
    );

    return new ListView(
      padding: const EdgeInsets.only(
        top: 12.0,
      ),
      children: items,
    );
  }

  ///
  /// Face Method
  ///
  Future<Null> _face() async {
    List<Face> faces = [];
    try {
      faces = await FlutterMobileVision.face(
        flash: _torchFace,
        autoFocus: _autoFocusFace,
        multiple: _multipleFace,
        showText: _showTextFace,
        camera: _cameraFace,
        fps: 15.0,
      );
    } on Exception {
      faces.add(new Face(-1));
    }

    if (!mounted) return;

    setState(() => _faces = faces);
  }
}

///
/// BarcodeWidget
///
class BarcodeWidget extends StatelessWidget {
  final Barcode barcode;

  BarcodeWidget(this.barcode);

  @override
  Widget build(BuildContext context) {
    return new ListTile(
      leading: const Icon(Icons.star),
      title: new Text(barcode.displayValue),
      subtitle: new Text(
        '${barcode.getFormatString()} (${barcode.format}) - '
            '${barcode.getValueFormatString()} (${barcode.valueFormat})',
      ),
      trailing: const Icon(Icons.arrow_forward),
      onTap: () => Navigator.of(context).push(
            new MaterialPageRoute(
              builder: (context) => new BarcodeDetail(barcode),
            ),
          ),
    );
  }
}

///
/// OcrTextWidget
///
class OcrTextWidget extends StatelessWidget {
  final OcrText ocrText;

  OcrTextWidget(this.ocrText);

  @override
  Widget build(BuildContext context) {
    return new ListTile(
      leading: const Icon(Icons.title),
      title: new Text(ocrText.value),
      subtitle: new Text(ocrText.language),
      trailing: const Icon(Icons.arrow_forward),
      onTap: () => Navigator.of(context).push(
            new MaterialPageRoute(
              builder: (context) => new OcrTextDetail(ocrText),
            ),
          ),
    );
  }
}

///
/// FaceWidget
///
class FaceWidget extends StatelessWidget {
  final Face face;

  FaceWidget(this.face);

  @override
  Widget build(BuildContext context) {
    return new ListTile(
      leading: const Icon(Icons.face),
      title: new Text(face.id.toString()),
      trailing: const Icon(Icons.arrow_forward),
      onTap: () => Navigator.of(context).push(
            new MaterialPageRoute(
              builder: (context) => new FaceDetail(face),
            ),
          ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_mobile_vision: ^0.1.1

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:flutter_mobile_vision/flutter_mobile_vision.dart';
  
Version Uploaded Documentation Archive
0.1.1 Jul 8, 2018 Go to the documentation of flutter_mobile_vision 0.1.1 Download flutter_mobile_vision 0.1.1 archive
0.1.0 May 7, 2018 Go to the documentation of flutter_mobile_vision 0.1.0 Download flutter_mobile_vision 0.1.0 archive
0.0.4 May 4, 2018 Go to the documentation of flutter_mobile_vision 0.0.4 Download flutter_mobile_vision 0.0.4 archive
0.0.3 May 2, 2018 Go to the documentation of flutter_mobile_vision 0.0.3 Download flutter_mobile_vision 0.0.3 archive
0.0.2 Apr 23, 2018 Go to the documentation of flutter_mobile_vision 0.0.2 Download flutter_mobile_vision 0.0.2 archive
0.0.1 Apr 23, 2018 Go to the documentation of flutter_mobile_vision 0.0.1 Download flutter_mobile_vision 0.0.1 archive
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]
100
Overall:
Weighted score of the above. [more]
92
Learn more about scoring.

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

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

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