Git Product home page Git Product logo

Comments (17)

SiddharthOza00 avatar SiddharthOza00 commented on May 24, 2024

Can you share your code please? @RobbyGit

from facerecognitionauth.

KALU-KELECHI-GABRIEL avatar KALU-KELECHI-GABRIEL commented on May 24, 2024

@SiddharthOza00 I had the same issue no face is detected on sign up but on the sign in everything seems fine. This is the sign-up.dart file.

import 'dart:async';
import 'dart:io';
import 'dart:math' as math;
import 'package:face_net_authentication/locator.dart';
import 'package:face_net_authentication/pages/widgets/FacePainter.dart';
import 'package:face_net_authentication/pages/widgets/auth-action-button.dart';
import 'package:face_net_authentication/pages/widgets/camera_header.dart';
import 'package:face_net_authentication/services/camera.service.dart';
import 'package:face_net_authentication/services/ml_service.dart';
import 'package:face_net_authentication/services/face_detector_service.dart';
import 'package:camera/camera.dart';
import 'package:google_ml_kit/google_ml_kit.dart';
import 'package:flutter/material.dart';

class SignUp extends StatefulWidget {
  const SignUp({Key key}) : super(key: key);

  @override
  SignUpState createState() => SignUpState();
}

class SignUpState extends State<SignUp> {
  String imagePath;
  Face faceDetected;
  Size imageSize;

  bool _detectingFaces = false;
  bool pictureTaken = false;

  bool _initializing = false;

  bool _saving = false;
  bool _bottomSheetVisible = false;

  // service injection
  FaceDetectorService _faceDetectorService = locator<FaceDetectorService>();
  CameraService _cameraService = locator<CameraService>();
  MLService _mlService = locator<MLService>();

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

  @override
  void dispose() {
    _cameraService.dispose();
    super.dispose();
  }

  _start() async {
    setState(() => _initializing = true);
    await _cameraService.initialize();
    setState(() => _initializing = false);

    _frameFaces();
  }

  Future<void> onShot() async {
    if (faceDetected == null) {
      showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            content: Text('No face detected!'),
          );
        },
      );

      return false;
    } else {
      _saving = true;
      await Future.delayed(Duration(milliseconds: 500));
      await _cameraService.cameraController.stopImageStream();
      await Future.delayed(Duration(milliseconds: 200));
      XFile file = await _cameraService.takePicture();
      imagePath = file.path;

      setState(() {
        _bottomSheetVisible = true;
        pictureTaken = true;
      });

      return true;
    }
  }

  _frameFaces() {
    imageSize = _cameraService.getImageSize();

    _cameraService.cameraController.startImageStream((image) async {
      if (_cameraService.cameraController != null) {
        if (_detectingFaces) return;

        _detectingFaces = true;

        try {
          await _faceDetectorService.detectFacesFromImage(image);

          if (_faceDetectorService.faces.isNotEmpty) {
            if (_saving) {
              _mlService.setCurrentPrediction(image, faceDetected);
              setState(() {
                _saving = false;
              });
            }
          } else {
            setState(() {
              faceDetected = null;
            });
          }

          _detectingFaces = false;
        } catch (e) {
          print(e);
          _detectingFaces = false;
        }
      }
    });
  }

  _onBackPressed() {
    Navigator.of(context).pop();
  }

  _reload() {
    setState(() {
      _bottomSheetVisible = false;
      pictureTaken = false;
    });
    this._start();
  }

  @override
  Widget build(BuildContext context) {
    final double mirror = math.pi;
    final width = MediaQuery.of(context).size.width;
    final height = MediaQuery.of(context).size.height;

    Widget body;
    if (_initializing) {
      body = Center(
        child: CircularProgressIndicator(),
      );
    }

    if (!_initializing && pictureTaken) {
      body = Container(
        width: width,
        height: height,
        child: Transform(
            alignment: Alignment.center,
            child: FittedBox(
              fit: BoxFit.cover,
              child: Image.file(File(imagePath)),
            ),
            transform: Matrix4.rotationY(mirror)),
      );
    }

    if (!_initializing && !pictureTaken) {
      body = Transform.scale(
        scale: 1.0,
        child: AspectRatio(
          aspectRatio: MediaQuery.of(context).size.aspectRatio,
          child: OverflowBox(
            alignment: Alignment.center,
            child: FittedBox(
              fit: BoxFit.fitHeight,
              child: Container(
                width: width,
                height:
                    width * _cameraService.cameraController.value.aspectRatio,
                child: Stack(
                  fit: StackFit.expand,
                  children: <Widget>[
                    CameraPreview(_cameraService.cameraController),
                    CustomPaint(
                      painter:
                          FacePainter(face: faceDetected, imageSize: imageSize),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      );
    }

    return Scaffold(
        body: Stack(
          children: [
            body,
            CameraHeader(
              "SIGN UP",
              onBackPressed: _onBackPressed,
            )
          ],
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
        floatingActionButton: !_bottomSheetVisible
            ? AuthActionButton(
                onPressed: onShot,
                isLogin: false,
                reload: _reload,
              )
            : Container());
  }
}

from facerecognitionauth.

SiddharthOza00 avatar SiddharthOza00 commented on May 24, 2024

I am getting these errors. Can someone help me? @RobbyGit @KALU-KELECHI-GABRIEL @guruhyes
Error2
Error1
Error3

from facerecognitionauth.

guruhyes avatar guruhyes commented on May 24, 2024

its because variable faceDetected not set in _frameFaces,
yo need to set faceDetected , see image below
file sign-up.dart
function _frameFaces()
image

I dunno its the right way or not, but its should work

from facerecognitionauth.

KALU-KELECHI-GABRIEL avatar KALU-KELECHI-GABRIEL commented on May 24, 2024

@guruhyes I added the line it still does not work as expected. If you could share your entire sign-up.dart file please.

from facerecognitionauth.

KALU-KELECHI-GABRIEL avatar KALU-KELECHI-GABRIEL commented on May 24, 2024

@SiddharthOza00 try setting ur android studio to point at the correct SDK version

follow the steps here
https://stackoverflow.com/questions/56938436/first-flutter-app-error-cannot-resolve-symbol-properties

from facerecognitionauth.

guruhyes avatar guruhyes commented on May 24, 2024

@KALU-KELECHI-GABRIEL

here is my code

`import 'dart:async';
import 'dart:io';
import 'dart:math' as math;
import 'package:face_net_authentication/locator.dart';
import 'package:face_net_authentication/pages/widgets/FacePainter.dart';
import 'package:face_net_authentication/pages/widgets/auth-action-button.dart';
import 'package:face_net_authentication/pages/widgets/camera_header.dart';
import 'package:face_net_authentication/services/camera.service.dart';
import 'package:face_net_authentication/services/ml_service.dart';
import 'package:face_net_authentication/services/face_detector_service.dart';
import 'package:camera/camera.dart';
import 'package:google_ml_kit/google_ml_kit.dart';
import 'package:flutter/material.dart';

class SignUp extends StatefulWidget {
const SignUp({Key key}) : super(key: key);

@OverRide
SignUpState createState() => SignUpState();
}

class SignUpState extends State {
String imagePath;
Face faceDetected;
Size imageSize;

bool _detectingFaces = false;
bool pictureTaken = false;

bool _initializing = false;

bool _saving = false;
bool _bottomSheetVisible = false;

// service injection
FaceDetectorService _faceDetectorService = locator();
CameraService _cameraService = locator();
MLService _mlService = locator();

@OverRide
void initState() {
super.initState();
_start();
}

@OverRide
void dispose() {
_cameraService.dispose();
super.dispose();
}

_start() async {
setState(() => _initializing = true);
await _cameraService.initialize();
setState(() => _initializing = false);

_frameFaces();

}

Future onShot() async {
if (faceDetected == null) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: Text('No face detected!'),
);
},
);

  return false;
} else {
  _saving = true;
  await Future.delayed(Duration(milliseconds: 500));
  //await _cameraService.cameraController.stopImageStream();
  //await Future.delayed(Duration(milliseconds: 200));
  XFile file = await _cameraService.takePicture();
  imagePath = file.path;

  setState(() {
    _bottomSheetVisible = true;
    pictureTaken = true;
  });

  return true;
}

}

_frameFaces() {
imageSize = _cameraService.getImageSize();

_cameraService.cameraController.startImageStream((image) async {
  if (_cameraService.cameraController != null) {
    if (_detectingFaces) return;

    _detectingFaces = true;

    try {
      await _faceDetectorService.detectFacesFromImage(image);

      if (_faceDetectorService.faces.isNotEmpty) {
        setState(() {
          faceDetected = _faceDetectorService.faces[0];
        });
        if (_saving) {
          _mlService.setCurrentPrediction(image, faceDetected);
          setState(() {
            _saving = false;
          });
        }
      } else {
        setState(() {
          faceDetected = null;
        });
      }

      _detectingFaces = false;
    } catch (e) {
      print(e);
      _detectingFaces = false;
    }
  }
});

}

_onBackPressed() {
Navigator.of(context).pop();
}

_reload() {
setState(() {
_bottomSheetVisible = false;
pictureTaken = false;
});
this._start();
}

@OverRide
Widget build(BuildContext context) {
final double mirror = math.pi;
final width = MediaQuery.of(context).size.width;
final height = MediaQuery.of(context).size.height;

Widget body;
if (_initializing) {
  body = Center(
    child: CircularProgressIndicator(),
  );
}

if (!_initializing && pictureTaken) {
  body = Container(
    width: width,
    height: height,
    child: Transform(
        alignment: Alignment.center,
        child: FittedBox(
          fit: BoxFit.cover,
          child: Image.file(File(imagePath)),
        ),
        transform: Matrix4.rotationY(mirror)),
  );
}

if (!_initializing && !pictureTaken) {
  body = Transform.scale(
    scale: 1.0,
    child: AspectRatio(
      aspectRatio: MediaQuery.of(context).size.aspectRatio,
      child: OverflowBox(
        alignment: Alignment.center,
        child: FittedBox(
          fit: BoxFit.fitHeight,
          child: Container(
            width: width,
            height:
                width * _cameraService.cameraController.value.aspectRatio,
            child: Stack(
              fit: StackFit.expand,
              children: <Widget>[
                CameraPreview(_cameraService.cameraController),
                CustomPaint(
                  painter:
                      FacePainter(face: faceDetected, imageSize: imageSize),
                ),
              ],
            ),
          ),
        ),
      ),
    ),
  );
}

return Scaffold(
    body: Stack(
      children: [
        body,
        CameraHeader(
          "SIGN UP",
          onBackPressed: _onBackPressed,
        )
      ],
    ),
    floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
    floatingActionButton: !_bottomSheetVisible
        ? AuthActionButton(
            onPressed: onShot,
            isLogin: false,
            reload: _reload,
          )
        : Container());

}
}
`

from facerecognitionauth.

KALU-KELECHI-GABRIEL avatar KALU-KELECHI-GABRIEL commented on May 24, 2024

thanks a lot @guruhyes . This works just had to change the @OverRide to @OverRide. Thank you.

from facerecognitionauth.

RobbyGit avatar RobbyGit commented on May 24, 2024

@KALU-KELECHI-GABRIEL Can you show me where you updated this

from facerecognitionauth.

KALU-KELECHI-GABRIEL avatar KALU-KELECHI-GABRIEL commented on May 24, 2024

@RobbyGit I don't understand the question

from facerecognitionauth.

SiddharthOza00 avatar SiddharthOza00 commented on May 24, 2024

If you have the code on your github can you share your updated project with the latest changes? @KALU-KELECHI-GABRIEL

from facerecognitionauth.

RobbyGit avatar RobbyGit commented on May 24, 2024

@KALU-KELECHI-GABRIEL Sorry I didnt finish. I added the lines that @guruhyes suggested and it does now see a face but I get when I hit capture. What do you get .

CameraException(No camera is streaming images, stopImageStream was called when no camera is streaming images.)

from facerecognitionauth.

RobbyGit avatar RobbyGit commented on May 24, 2024

@KALU-KELECHI-GABRIEL . I commented out await _cameraService.cameraController.stopImageStream(); and now its working .. Have to see what else has broken

from facerecognitionauth.

guruhyes avatar guruhyes commented on May 24, 2024

@KALU-KELECHI-GABRIEL . I commented out await _cameraService.cameraController.stopImageStream(); and now its working .. Have to see what else has broken

Yes commented will work, take a look to my code function onShot()

from facerecognitionauth.

SiddharthOza00 avatar SiddharthOza00 commented on May 24, 2024

Can someone help me with the errors in the images I sent before?

from facerecognitionauth.

KALU-KELECHI-GABRIEL avatar KALU-KELECHI-GABRIEL commented on May 24, 2024

Can someone help me with the errors in the images I sent before?

I did check up

from facerecognitionauth.

MCarlomagno avatar MCarlomagno commented on May 24, 2024

Hi Guys, sorry for the late answer, I just updated the project to null safety. I'm going to work on the issues found later, thanks for contribuiting!

from facerecognitionauth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.