google_vision_flutter 1.0.0+2 google_vision_flutter: ^1.0.0+2 copied to clipboard
Add Google Visions image labeling, face, logo, and landmark detection into your Flutter applications.
Google Vision Images Flutter Widget #
Native Dart package that integrates Google Vision features, including image labeling, face, logo, and landmark detection into Flutter applications.
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 #
Getting Started #
pubspec.yaml #
To use this package, add the dependency to your pubspec.yaml
file:
dependencies:
...
google_vision_flutter: ^1.2.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 GoogleVisionBuilder Widget #
See the example app for the full code.
import 'package:flutter/material.dart';
import 'package:google_vision_flutter/google_vision_flutter.dart';
class FaceDetection extends StatefulWidget {
const FaceDetection({super.key, required this.title});
final String title;
@override
State<FaceDetection> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<FaceDetection> {
final _processImage = Image.asset(
'assets/young-man-smiling.jpg',
fit: BoxFit.fitWidth,
);
@override
Widget build(BuildContext context) => SafeArea(
child: Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.black),
onPressed: () => Navigator.of(context).pop(),
),
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
const Padding(
padding: EdgeInsets.all(8.0),
child: Text('assets/young-man-smiling.jpg'),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: _processImage,
),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Processed image will appear below:',
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: GoogleVisionBuilder.faceDetection(
googleVision: GoogleVision.withAsset(
'assets/service_credentials.json'),
imageProvider: _processImage.image,
builder: (BuildContext context,
List<FaceAnnotation>? faceAnnotations,
ImageDetail imageDetail) {
return CustomPaint(
foregroundPainter: AnnotationPainter(
faceAnnotations: faceAnnotations,
imageDetail: imageDetail,
),
child: Image(image: _processImage.image),
);
},
),
)
],
),
),
),
);
}
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.