google_vision 1.0.6 google_vision: ^1.0.6 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 #
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.
- Cloud Vision API - Documentation Reference
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
- Getting Started
- vision cli (google_vision at the command prompt)
- Contributors
- Contributing
Recent Changes #
New for v1.0.6 #
imhafeez has provided code for Safe Search
functionality.
New for v1.0.3 #
4ctobias has provided code for Label Detection
functionality.
Getting Started #
pubspec.yaml #
To use this package, add the dependency to your pubspec.yaml
file:
dependencies:
...
google_vision: ^1.0.6
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 =
Image.fromFilePath('example/young-man-smiling-and-thumbs-up.jpg');
// cropping an image can save time uploading the image to Google
final cropped = image.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) {
GoogleVision.drawText(
cropped,
faceAnnotation.boundingPoly.vertices.first.x + 2,
faceAnnotation.boundingPoly.vertices.first.y + 2,
'Face - ${faceAnnotation.detectionConfidence}');
GoogleVision.drawAnnotations(
cropped, faceAnnotation.boundingPoly.vertices);
}
}
for (var annotatedResponse in annotatedResponses.responses) {
//look only for Person annotations
annotatedResponse.localizedObjectAnnotations
.where((localizedObjectAnnotation) =>
localizedObjectAnnotation.name == 'Person')
.toList()
.forEach((localizedObjectAnnotation) {
GoogleVision.drawText(
cropped,
(localizedObjectAnnotation.boundingPoly.normalizedVertices.first.x *
cropped.width)
.toInt(),
(localizedObjectAnnotation.boundingPoly.normalizedVertices.first.y *
cropped.height)
.toInt() -
16,
'Person - ${localizedObjectAnnotation.score}');
GoogleVision.drawAnnotationsNormalized(
cropped, localizedObjectAnnotation.boundingPoly.normalizedVertices);
});
}
// output the results as a new image file
await cropped.writeAsJpeg('resulting_image.jpg');
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
Result,
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:
detect Run image detection and annotation for an images.
highlight Draw a box to highlight any objects detected.
score For OBJECT_LOCALIZATION, get the score(s) for the object specified with "look-for".
Please see the cli documentation README.md 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.