Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
faithoflifedev committed Aug 30, 2024
1 parent 86a1d83 commit ad79c61
Show file tree
Hide file tree
Showing 16 changed files with 405 additions and 272 deletions.
14 changes: 7 additions & 7 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ scripts:
# run: melos run publish:dart && melos run publish:flutter
# description: Run publish for all packages.

prep:dart:
run: melos run build && melos run meta && melos run markdown && melos run analyze && melos run format
description: Run prep steps dart.
prep:
run: melos run build && melos run meta && melos run markdown && melos run format && melos run analyze
description: Run prep steps for dart and flutter.

prep:flutter:
run: melos run build && melos run meta && melos run markdown && melos run analyze && melos run format
description: Run prep steps Flutter.
# prep:flutter:
# run: melos run build && melos run meta && melos run markdown && melos run analyze && melos run format
# description: Run prep steps Flutter.

## TODO: Add commit steps for Dart and Flutter packages.

Expand Down Expand Up @@ -66,7 +66,7 @@ scripts:
depends-on: build_runner

analyze:
exec: dart analyze --fatal-infos .
exec: dart analyze .
description: Run `dart analyze` in all packages.

format:
Expand Down
2 changes: 1 addition & 1 deletion packages/google_vision/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: google_vision
description: Allows you to add Google Visions image labeling, face, logo, and landmark detection, OCR, and detection of explicit content, into cross platform applications.
version: 1.3.0+3
version: 1.3.0+4
repository: https://github.com/faithoflifedev/google_vision
homepage: https://github.com/faithoflifedev/google_vision/tree/main/packages/google_vision

Expand Down
5 changes: 4 additions & 1 deletion packages/google_vision/tool/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Google Vision Images REST API Client


[![pub package](https://img.shields.io/pub/v/google_vision.svg)](https://pub.dartlang.org/packages/google_vision)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Native [Dart](https://dart.dev/) 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.

- [Google Vision Images REST API Client](#google-vision-images-rest-api-client)
Expand All @@ -21,7 +25,6 @@ Native [Dart](https://dart.dev/) package that integrates Google Vision features,

## Project Status

[![pub package](https://img.shields.io/pub/v/google_vision.svg)](https://pub.dartlang.org/packages/google_vision)

[![Build Status](https://github.com/faithoflifedev/google_vision/workflows/Dart/badge.svg)](https://github.com/faithoflifedev/google_vision/actions) [![github last commit](https://shields.io/github/last-commit/faithoflifedev/google_vision)](https://shields.io/github/last-commit/faithoflifedev/google_vision) [![github build](https://img.shields.io/github/actions/workflow/status/faithoflifedev/google_vision_workspace/dart.yaml?branch=main)](https://shields.io/github/workflow/status/faithoflifedev/google_vision/Dart) [![github issues](https://shields.io/github/issues/faithoflifedev/google_vision)](https://shields.io/github/issues/faithoflifedev/google_vision)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions packages/google_vision_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'label_detection.dart';
import 'landmark_detection.dart';
import 'logo_detection.dart';
import 'multiple_detections.dart';
import 'multiple_face_detections.dart';
import 'object_localization.dart';
import 'safe_search_detection.dart';
import 'text_detection.dart';
Expand Down Expand Up @@ -66,6 +67,9 @@ class MyApp extends StatelessWidget {
'/webdetection': (context) => const WebDetection(
title: 'Document Text Detection from PDF',
),
'/multipleface': (context) => const MultipleFaceDetection(
title: 'Multiple Image Face Detection',
),
},
);
}
Expand Down Expand Up @@ -140,6 +144,10 @@ class MenuScreen extends StatelessWidget {
child: const Text('Web Detection'),
onPressed: () => Navigator.pushNamed(context, '/webdetection'),
),
ElevatedButton(
child: const Text('Multiple Image Face Detection'),
onPressed: () => Navigator.pushNamed(context, '/multipleface'),
),
const SizedBox(
height: 30,
child: Text('File Functions'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class MultipleDetections extends StatefulWidget {
}

class _MyHomePageState extends State<MultipleDetections> {
static const assetName = 'assets/young-man-smiling.jpg';

final _processImage = Image.asset(
'assets/young-man-smiling.jpg', // 'assets/logo.png', // 'assets/young-man-smiling.jpg'
assetName,
fit: BoxFit.fitWidth,
width: 300,
);
Expand All @@ -34,7 +36,7 @@ class _MyHomePageState extends State<MultipleDetections> {
children: <Widget>[
const Padding(
padding: EdgeInsets.all(8.0),
child: Text('assets/young-man-smiling'),
child: Text(assetName),
),
const Padding(
padding: EdgeInsets.all(8.0),
Expand Down Expand Up @@ -62,13 +64,11 @@ class _MyHomePageState extends State<MultipleDetections> {
features: [
Feature(
maxResults: 10,
type: AnnotationType
.faceDetection, // 'LOGO_DETECTION', // 'FACE_DETECTION'
type: AnnotationType.faceDetection,
),
Feature(
maxResults: 10,
type: AnnotationType
.objectLocalization, // 'LOGO_DETECTION', // 'FACE_DETECTION'
type: AnnotationType.objectLocalization,
),
],
builder: (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:google_vision/google_vision.dart' as gv;
import 'package:google_vision_flutter/google_vision_flutter.dart';

class MultipleFaceDetection extends StatefulWidget {
const MultipleFaceDetection({super.key, required this.title});

final String title;

@override
State<MultipleFaceDetection> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MultipleFaceDetection> {
FutureOr<gv.GoogleVision>? _googleVision;

static const assetName1 = 'assets/young-man-smiling.jpg';

static const assetName2 = 'assets/dj.jpg';

final _processImage1 = Image.asset(
assetName1,
fit: BoxFit.fitWidth,
height: 300,
);

final _processImage2 = Image.asset(
assetName2,
fit: BoxFit.fitWidth,
height: 300,
);

@override
void initState() {
super.initState();

WidgetsBinding.instance.addPostFrameCallback((_) {
_getGoogleVision();
});
}

FutureOr<void> _getGoogleVision() async {
_googleVision ??= await GoogleVision.withAsset(
'assets/service_credentials.json',
);

setState(() {});
}

@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: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(children: [
const Padding(
padding: EdgeInsets.all(8.0),
child: Text(assetName1),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: _processImage1,
),
]),
Column(children: [
const Padding(
padding: EdgeInsets.all(8.0),
child: Text(assetName2),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: _processImage2,
),
]),
],
),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Processed images will appear below:',
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: _googleVision == null
? const CircularProgressIndicator()
: GoogleVisionImageBuilder.faceDetection(
googleVision: _googleVision!,
imageProvider: _processImage1.image,
builder: (
BuildContext context,
List<FaceAnnotation>? faceAnnotations,
) =>
CustomPaint(
foregroundPainter: AnnotationPainter(
faceAnnotations: faceAnnotations,
),
child: Image(image: _processImage1.image),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: _googleVision == null
? const CircularProgressIndicator()
: GoogleVisionImageBuilder.faceDetection(
googleVision: Future.value(_googleVision),
imageProvider: _processImage2.image,
builder: (
BuildContext context,
List<FaceAnnotation>? faceAnnotations,
) =>
CustomPaint(
foregroundPainter: AnnotationPainter(
faceAnnotations: faceAnnotations,
),
child: Image(image: _processImage2.image),
),
),
)
],
),
),
),
),
);
}

class AnnotationPainter extends CustomPainter {
final List<FaceAnnotation>? faceAnnotations;

AnnotationPainter({
required this.faceAnnotations,
});

@override
void paint(
Canvas canvas,
Size size,
) {
// face detection
for (var faceAnnotation in faceAnnotations!) {
drawAnnotationsRect(
vertices: faceAnnotation.boundingPoly.vertices,
canvas: canvas,
);

drawString(
text: 'Face - ${(faceAnnotation.detectionConfidence * 100).toInt()}%',
offset: faceAnnotation.boundingPoly.vertices.first.toOffset(),
canvas: canvas,
size: size,
);
}
}

void drawString({
required String text,
required Offset offset,
required Canvas canvas,
required Size size,
Color? color,
}) {
color ??= Colors.red.shade900;

final tp = TextPainter(
text: TextSpan(
text: text,
style: TextStyle(color: color),
),
textAlign: TextAlign.left,
textDirection: TextDirection.ltr,
);

tp.layout();

tp.paint(canvas, offset);
}

void drawAnnotationsRect({
required List<Vertex> vertices,
required Canvas canvas,
Color? color,
double strokeWidth = 1,
}) {
color ??= Colors.red.shade400;

final paint = Paint();

paint.style = PaintingStyle.stroke;
paint.strokeWidth = strokeWidth;
paint.color = color;

canvas.drawRect(
Rect.fromPoints(
vertices.first.toOffset(),
vertices[2].toOffset(),
),
paint,
);
}

@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}
2 changes: 2 additions & 0 deletions packages/google_vision_flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ environment:

dependencies:
color: ^3.0.0
google_vision: ^1.3.0+2
google_vision_flutter:
path: ../
syncfusion_flutter_pdfviewer: ^26.2.11
Expand All @@ -28,6 +29,7 @@ flutter:
- assets/allswell.pdf
- assets/census2010.jpg
- assets/cn_tower.jpg
- assets/dj.jpg # https://commons.wikimedia.org/wiki/Category:Images#/media/File:DJ_Kelblizz.jpg
- assets/google_logo.jpg
- assets/service_credentials.json
- assets/setagaya_small.jpg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export 'src/google_vision.dart';
export 'src/google_vision_builder_base.dart';
export 'src/google_vision_builder.dart';
export 'src/google_vision_file_builder.dart';
export 'src/google_vision_future_resolver.dart';
export 'src/google_vision_image_builder.dart';
export 'src/image_detail.dart';
export 'src/input_config.dart';
Expand Down
2 changes: 1 addition & 1 deletion packages/google_vision_flutter/lib/src/google_vision.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class GoogleVision extends gv.GoogleVision {
}

/// Create a new instance of [GoogleVision] with the given [apiKey].
static Future<gv.GoogleVision> withApiKey(String apiKey) async =>
static gv.GoogleVision withApiKey(String apiKey) =>
gv.GoogleVision.withApiKey(apiKey);
}
Loading

0 comments on commit ad79c61

Please sign in to comment.