Skip to content

Commit

Permalink
Code Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sayannath committed Sep 13, 2021
1 parent bd6bb81 commit 298b79b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 49 deletions.
Binary file modified assets/images/logo_mahindra.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 12 additions & 10 deletions lib/pages/sign-in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class SignInState extends State<SignIn> {

/// starts the camera & start framing faces
_start() async {
_initializeControllerFuture = _cameraService.startService(widget.cameraDescription);
_initializeControllerFuture =
_cameraService.startService(widget.cameraDescription);
await _initializeControllerFuture;

setState(() {
Expand Down Expand Up @@ -97,7 +98,6 @@ class SignInState extends State<SignIn> {
_saving = false;
_faceNetService.setCurrentPrediction(image, faceDetected);
}

} else {
setState(() {
faceDetected = null;
Expand All @@ -114,19 +114,19 @@ class SignInState extends State<SignIn> {
});
}

/// handles the button pressed event
//handles the button pressed event
Future<void> onShot() async {

if (faceDetected == null) {
showDialog(
context: context,
child: AlertDialog(
content: Text('No face detected!'),
));
builder: (_) => AlertDialog(
content: Text('No face detected!'),
));

return false;
} else {
imagePath = join((await getTemporaryDirectory()).path, '${DateTime.now()}.png');
imagePath =
join((await getTemporaryDirectory()).path, '${DateTime.now()}.png');

_saving = true;

Expand Down Expand Up @@ -172,13 +172,15 @@ class SignInState extends State<SignIn> {
fit: BoxFit.fitHeight,
child: Container(
width: width,
height: width / _cameraService.cameraController.value.aspectRatio,
height: width /
_cameraService.cameraController.value.aspectRatio,
child: Stack(
fit: StackFit.expand,
children: <Widget>[
CameraPreview(_cameraService.cameraController),
CustomPaint(
painter: FacePainter(face: faceDetected, imageSize: imageSize),
painter: FacePainter(
face: faceDetected, imageSize: imageSize),
)
],
),
Expand Down
6 changes: 3 additions & 3 deletions lib/pages/sign-up.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class SignUpState extends State<SignUp> {
if (faceDetected == null) {
showDialog(
context: context,
child: AlertDialog(
content: Text('No face detected!'),
));
builder: (_) => AlertDialog(
content: Text('No face detected!'),
));

return false;
} else {
Expand Down
20 changes: 11 additions & 9 deletions lib/services/facenet.service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:camera/camera.dart';
import 'package:firebase_ml_vision/firebase_ml_vision.dart';
import 'package:tflite_flutter/tflite_flutter.dart' as tflite;
import 'package:image/image.dart' as imglib;
import 'package:tflite_flutter/tflite_flutter.dart';

class FaceNetService {
// singleton boilerplate
Expand All @@ -30,15 +31,16 @@ class FaceNetService {

Future loadModel() async {
try {
final gpuDelegateV2 = tflite.GpuDelegateV2(
options: tflite.GpuDelegateOptionsV2(
false,
tflite.TfLiteGpuInferenceUsage.fastSingleAnswer,
tflite.TfLiteGpuInferencePriority.minLatency,
tflite.TfLiteGpuInferencePriority.auto,
tflite.TfLiteGpuInferencePriority.auto));

var interpreterOptions = tflite.InterpreterOptions()..addDelegate(gpuDelegateV2);
// final gpuDelegateV2 = GpuDelegateV2(
// options: GpuDelegateOptionsV2(
// TfLiteGpuInferenceUsage.fastSingleAnswer,
// TfLiteGpuInferencePriority.minLatency,
// TfLiteGpuInferencePriority.auto,
// TfLiteGpuInferencePriority.auto,
// ));

var interpreterOptions = tflite.InterpreterOptions();
// ..addDelegate(gpuDelegateV2);
this._interpreter = await tflite.Interpreter.fromAsset('mobilefacenet.tflite', options: interpreterOptions);
print('model loaded successfully');
} catch (e) {
Expand Down
59 changes: 33 additions & 26 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0-nullsafety.1"
version: "2.6.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.1"
version: "2.1.0"
camera:
dependency: "direct main"
description:
Expand All @@ -42,28 +42,28 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.3"
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.1"
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0-nullsafety.3"
version: "1.15.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -91,14 +91,14 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0"
ffi:
dependency: transitive
description:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "1.1.2"
file:
dependency: transitive
description:
Expand Down Expand Up @@ -142,27 +142,34 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.16.1"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10-nullsafety.1"
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0"
path:
dependency: "direct main"
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.1"
version: "1.8.0"
path_provider:
dependency: "direct main"
description:
Expand Down Expand Up @@ -197,7 +204,7 @@ packages:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4+3"
version: "0.0.5"
petitparser:
dependency: transitive
description:
Expand Down Expand Up @@ -232,7 +239,7 @@ packages:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.5"
version: "3.0.1"
shared_preferences:
dependency: "direct main"
description:
Expand Down Expand Up @@ -274,7 +281,7 @@ packages:
name: shared_preferences_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.2+2"
version: "0.0.2+3"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -286,70 +293,70 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.2"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.1"
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.1"
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.1"
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19-nullsafety.2"
version: "0.3.0"
tflite_flutter:
dependency: "direct main"
description:
name: tflite_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.0"
version: "0.9.0"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.3"
version: "2.1.0"
win32:
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.4+1"
version: "2.2.9"
xdg_directories:
dependency: transitive
description:
Expand All @@ -365,5 +372,5 @@ packages:
source: hosted
version: "4.2.0"
sdks:
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"
dart: ">=2.13.0 <3.0.0"
flutter: ">=1.26.0-17.6.pre"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies:
path: ^1.7.0
path_provider: ^1.6.27
shared_preferences: ^0.5.12+4
tflite_flutter: ^0.5.0
tflite_flutter: ^0.9.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 298b79b

Please sign in to comment.