简体   繁体   中英

How to use google ml kit for image labelling in flutter?

how to add the image labelling feature with google ml kit package into the flutter app, there is no examples for that, all examples that shown for me they was using firebase ml kit!

So how can we implement this ?

google_ml_kit is pretty new. Take a look at pub.dev example https://pub.dev/packages/google_ml_kit/example

Google ML Kit Basic (Imp. update): google_ml_kit package has all the functionalities like text recognition, image labelling, barcode scanning, face detection. so app size is getting increased. Recently creator of this packages split it into sub packages specific to the functionality. Now due to the sub packages app size issue doesn't occurred as we can use the required package instead of using the whole package.

So for image labelling, you can use google_mlkit_image_labeling package which is split from google_ml_kit package.

Code for Image Labelling: For image labelling, you can use below code snippet,

XFile image = await ImagePicker().pickImage(ImageSource.Gallery); //Get image using image picker
final InputImage inputImage = InputImage.fromFilePath(image.path); //Get input image object
final ImageLabelerOptions options = ImageLabelerOptions(confidenceThreshold: 0.5);//ImageLabeler option is required to set confident threshold, if we want labels above any confidence, we can set threshold here. confidence is a probability of a label.
final imageLabeler = ImageLabeler(options: options);
final List<ImageLabel> labels = await imageLabeler.processImage(inputImage);

for (ImageLabel label in labels) {
  final String text = label.text; // Image Label
  final double confidence = label.confidence; // Label Confidence, confidence is a probability of label
}

Along with this you need to have some configuration. To know more about the required configuration & to understand image labelling code in details with example, refer this link .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM