Skip to content

A flutter widget that show the camera stream and allow ML vision recognition on it, it allow you to detect barcodes, labels, text, faces...

License

Notifications You must be signed in to change notification settings

GDSC-HSU/flutter_camera_ml_vision

 
 

Repository files navigation

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: ^3.0.1
...

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 'GoogleMLKit/BarcodeScanning'
pod 'GoogleMLKit/FaceDetection'
pod 'GoogleMLKit/ImageLabeling'
pod 'GoogleMLKit/TextRecognition'

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.mlkit:image-labeling:17.0.5'
    }
}

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.mlkit.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: GoogleMlKit.vision.barcodeScanner().processImage,
  onResult: (List<Barcode> barcodes) {
    if (!mounted || resultSent) {
      return;
    }
    resultSent = true;
    Navigator.of(context).pop<Barcode>(barcodes.first);
  },
)

CameraMlVision is a widget that shows the preview of the camera. It takes a detector as a parameter; here we pass the processImage method of the BarcodeScanner object. The detector parameter can take all the different MLKit Vision Detectors. Here is a list :

GoogleMlKit.vision.barcodeScanner().processImage
GoogleMlKit.vision.imageLabeler().processImage
GoogleMlKit.vision.faceDetector().processImage
GoogleMlKit.vision.textDetector().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 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.

About

A flutter widget that show the camera stream and allow ML vision recognition on it, it allow you to detect barcodes, labels, text, faces...

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dart 91.3%
  • Ruby 5.0%
  • Objective-C 2.4%
  • Java 1.3%