google_vision 1.1.0+1 icon indicating copy to clipboard operation
google_vision: ^1.1.0+1 copied to clipboard

Allows you to add Google Visions image labeling, face, logo, and landmark detection, OCR, and detection of explicit content, into applications.

Google Vision Images REST API Client #

pub package

Native Dart package that integrates Google Vision features, including image labeling, face, logo, and landmark detection, optical character recognition (OCR), and detection of explicit content, into applications.

Build Status github last commit github build github issues

Please feel free to submit PRs for any additional helper methods, or report an issue for a missing helper method and I'll add it if I have time available.

Table of Contents #

Recent Changes #

New for v1.1.0 #

  • HighLiuk has contributed code that fills out some of the overall functionality
  • Breaking Change: The GoogleVision api has changed. To generate an auth token from a String the constructor GoogleVision.withJwt(String credentialsJsonAsString) should now be used, and for a file GoogleVision.withJwtFile(String credentialsFilename)
  // In your Flutter app
  final credentialsJsonAsString =
      await rootBundle.loadString('assets/service_credentials.json');

  final googleVision = await GoogleVision.withJwt(credentialsJsonAsString);

This change reflects the fact that the more common use case of the package is with Flutter

New for v1.0.8 #

New for v1.0.7 #

JLuisRojas has provided code for:

  • detect text in images
  • detect handwriting in images

In addition support for the following has also been added:

  • detect crop hints
  • detect image properties
  • detect landmarks
  • detect logos

New for v1.0.6 #

imhafeez has provided code for Safe Search functionality.

Getting Started #

pubspec.yaml #

To use this package, add the dependency to your pubspec.yaml file:

  google_vision: ^1.1.0+1

Obtaining Authorization Credentials #

Authenticating to the Cloud Vision API requires a JSON file with the JWT token information, which you can obtain by creating a service account in the API console.

Usage of the Cloud Vision API #

final googleVision =
    await GoogleVision.withJwt('my_jwt_credentials.json');

final image =

// cropping an image can save time uploading the image to Google
final cropped = painter.copyCrop(70, 30, 640, 480);

// to see the cropped image
await cropped.writeAsJpeg('example/cropped.jpg');

final requests = AnnotationRequests(requests: [
  AnnotationRequest(image: cropped, features: [
    Feature(maxResults: 10, type: 'FACE_DETECTION'),
    Feature(maxResults: 10, type: 'OBJECT_LOCALIZATION')

final annotatedResponses =
    await googleVision.annotate(requests: requests);

for (var annotatedResponse in annotatedResponses.responses) {
  for (var faceAnnotation in annotatedResponse.faceAnnotations) {
        faceAnnotation.boundingPoly.vertices.first.x + 2,
        faceAnnotation.boundingPoly.vertices.first.y + 2,
        'Face - ${faceAnnotation.detectionConfidence}');

        cropped, faceAnnotation.boundingPoly.vertices);

for (var annotatedResponse in annotatedResponses.responses) {
      .where((localizedObjectAnnotation) =>
 == 'Person')
      .forEach((localizedObjectAnnotation) {
        (localizedObjectAnnotation.boundingPoly.normalizedVertices.first.x *
        (localizedObjectAnnotation.boundingPoly.normalizedVertices.first.y *
                .toInt() -
        'Person - ${localizedObjectAnnotation.score}');

        cropped, localizedObjectAnnotation.boundingPoly.normalizedVertices);

// output the results as a new image file
await cropped.writeAsJpeg('resulting_image.jpg');

Usage with Flutter #

For a quick intro into the use of this package in a Flutter app see take a look at the vision_demo sample app in the example/flutter folder of the project's GitHub repository.

In getting the package to work with Flutter it's usually necessary to convert an object that is presented as an Asset or a Stream into a File for use by the google_vision package. The vision_demo app gives sample code that shows how to convert an Asset into a File. A similar process can be used for any Stream of data that represents an image supported by google_vision.

Vision cli (google_vision at the command prompt) #

This package included a cli utility that can be used to return data for any API call currently supported by the package. If you want to get started quickly with the cli utility run these commands in a terminal session:

Install using dart pub:

dart pub global activate google_vision

Install using brew:

brew tap faithoflifedev/google_vision
brew install vision

Run the following command to see help:

vision --help


A command line interface for making API requests to the Google Vision.

Usage: vision <command> [arguments]

Global options:
-h, --help                                       Print this usage information.
    --credential-file=<credentials file path>    (defaults to "/Users/chris/.vision/credentials.json")

Available commands:
  crop_hints  Set of crop hints that are used to generate new crops when serving images.
  detect      Run image detection and annotation for an images.
  highlight   Draw a box to highlight any objects detected.
  safe_search SafeSearch Detection detects explicit content such as adult content or violent content within an image.
  score       For OBJECT_LOCALIZATION, get the score(s) for the object specified with "look-for".

Please see the cli documentation for more detailed usage information.

Contributors #

Contributing #

Any help from the open-source community is always welcome and needed:

  • Found an issue?
    • Please fill a bug report with details.
  • Need a feature?
    • Open a feature request with use cases.
  • Are you using and liking the project?
    • Promote the project: create an article or post about it
    • Make a donation
  • Do you have a project that uses this package
    • let's cross promote, let me know and I'll add a link to your project
  • Are you a developer?
    • Fix a bug and send a pull request.
    • Implement a new feature.
    • Improve the Unit Tests.
  • Have you already helped in any way?
    • Many thanks from me, the contributors and everybody that uses this project!

If you donate 1 hour of your time, you can contribute a lot, because others will do the same, just be part and start with your 1 hour.

pub points


verified publisher

Allows you to add Google Visions image labeling, face, logo, and landmark detection, OCR, and detection of explicit content, into applications.

Repository (GitHub)
View/report issues


API reference


Icon for licenses.MIT (LICENSE)


args, color, crypto_keys, dio, http, image, jose, json_annotation, retrofit, universal_io


Packages that depend on google_vision