Image Labeling Using Google ML Kit in Flutter

Updated 27 April 2023

Save

In this article, we are going to learn Image recognition from the camera in Flutter.

Image Labeling

Image labeling gives you insight into the content of images. With ML Kit’s image labeling APIs, we can detect and extract information about entities in an image across a broad group of categories. The default image labeling model can identify general objects, places, activities, animal species, products, and more. Please check Google ML Kit for more on Image Labeling.

You may also check our Flutter app development page.

Using ML Kit For Image Labeling In Flutter

For text recognition using Google ML Kit check out this blog.

For image labeling in Flutter, we are going to use these flutter plugins: google_ml_kit and camera.

google_ml_kit: for the text recognition and many more, please check the official pub here.

camera: for accessing the device cameras, image stream which we are going to use later and for more check here.

Before we get started read about the platform-specific requirements here and known issues of the google_ml_kit plugin here.

We start by adding these plugins to our project’s pubspec.yaml file:

After adding the plugins, import them into your camera_screen.dart file like:

Now define your camera controller and initialize it inside initState method and Initialize ImageLabeler like this:

Once the camera is initialized, we start streaming images from the platform camera using the startImageStream method and pass the _processCameraImage method which is defined below as the parameter to it:

As you can see in the above code, imageLabeler.processImage(inputImage) is the main method for labeling the image and requires an InputImage type image as a parameter so first, we need to get the InputImage for the recognition from the CameraImage and we are getting this using getInputImage(image) method defined below:

Now create your CameraPreview widget for creating a preview widget for the given camera controller. and pass the above-defined CameraController like:

And put the above camera preview widget inside your build method like any other widget and that’s it.

Thanks for reading.

Happy Coding 🙂

For more Flutter tutorials visit Mobikul Blogs.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home