Face Mask Detection mobile application built with Flutter and TensorFlow lite in order to detect face masks using images and live camera.

Overview

Logo

Face Mask Detector App

Face Mask Detection mobile application built with Flutter and TensorFlow lite in order to detect face masks using images and live camera.

Features

  • Detect mask on the live detectoin.
  • Detect mask from a photo (camera or gallery)

Installation

1- Install Packages

image_picker: pick image from gallery
https://pub.dev/packages/image_picker
tflite: run our trained model
https://pub.dev/packages/tflite
camera: get the streaming image buffers
https://pub.dev/packages/camera
  1. Configure Project Android
android/app/build.gradle

android {
    ...
    aaptOptions {
        noCompress 'tflite'
        noCompress 'lite'
    }
    ...
}

minSdkVersion 21

  1. Train our model
* Download the dataset for training
    https://www.kaggle.com/prasoonkottarathil/face-mask-lite-dataset

* Training
    - go to https://teachablemachine.withgoogle.com to train our model
    - Get Started
    - Image Project
    - Edit `Class 1` for any Label(example `With_Mask`)
    - Edit `Class 2` for any Label(example `Without_Mask`)
    - Update image from dataset download above
    - Click `Train Model`(using default config) and waiting...
    - Click `Export Model` and select `Tensorflow Lite`
    - Download (include: *.tflite, labels.txt)

4. Load model
loadModel() async {
    Tflite.close();
    await Tflite.loadModel(
        model: "assets/model/model.tflite", 
        labels: "assets/model/labels.txt",
        //numThreads: 1, // defaults to 1
        //isAsset: true, // defaults: true, set to false to load resources outside assets
        //useGpuDelegate: false // defaults: false, use GPU delegate
    );
  }

5. Logic for Run Model on Image from (Camera or Gallery).
  _loadImage({required bool isCamera}) async {
    try {
      final XFile? image = await _picker.pickImage(
        source: isCamera ? ImageSource.camera : ImageSource.gallery,
      );
      if (image == null) {
        return null;
      }
      _image = File(image.path);
      _detectImage(_image!);
    } catch (e) {
      checkPermissions(context);
    }
  }
  _detectImage(File image) async {
    var recognitions = await Tflite.runModelOnImage(
      path: image.path,
      numResults: 2,
      threshold: 0.6,
      imageMean: 127.5,
      imageStd: 127.5,
    );
    setState(() {
      _loading = false;
      _recognitions = recognitions!;
      print(_recognitions[0]);
    });
  }
  1. Logic for Run Model on Image Stream (Live Detection).

Global Variables

  List? cameras; //Global Variable
  cameras = await availableCameras(); //init this in main before run app.

Live Detector Screen

  CameraImage? cameraImage;
  CameraController? cameraController;
  String outPut = "";
  int selectedCamera = 0;

  _toggleCameras() async {
    setState(() {
      selectedCamera = selectedCamera == 1 ? 0 : 1;
    });
    _initCamera();
  }

_initCamera() {
  cameraController =
      CameraController(cameras![selectedCamera], ResolutionPreset.max);
  cameraController!.initialize().then((value) {
    if (!mounted) {
      return;
    }
    setState(() {
      cameraController!.startImageStream((imageStream) {
        cameraImage = imageStream;
        _runModelOnFrame();
      });
    });
  });
}


_runModelOnFrame() async {
  if (cameraImage != null) {
    var recognitions = await Tflite.runModelOnFrame(
      bytesList: cameraImage!.planes.map((plane) {
        return plane.bytes;
      }).toList(),
      imageHeight: cameraImage!.height,
      imageWidth: cameraImage!.width,
      imageMean: 127.5,
      imageStd: 127.5,
      rotation: 90,
      numResults: 2,
    );
    for (var recognition in recognitions!) {
      outPut = recognitionResult(recognition);
      setState(() {});
    }
  }
}

With Mask (100%)">
Output format:
  [{
    index: 0,
    label: "With_Mask",
    confidence: 0.989
  },...]

  Get the Output from this simple function:

    recognitionResult(recognition) {
    double confidence = (recognition['confidence'] * 100);
    var label = recognition['label'].split("_").join(" ");
    return "$label (${confidence.roundToDouble()}%)";
    }

  Output --> With Mask (100%)

Screenshots


Download APK

Download APK File and install it, Enjoy.

Download zip

You might also like...

A group of overlapping round avatars are called face piles, a face pile is a series of overlapping avatar images that come and go as users join and leave a given group.

A group of overlapping round avatars are called face piles, a face pile is a series of overlapping avatar images that come and go as users join and leave a given group.

Flutter Face Pile A group of overlapping round avatars are called face piles. A face pile is a series of overlapping avatar images that come and go as

Sep 22, 2022

Real-time object detection in Flutter using camera and tflite plugin

Real-time object detection in Flutter using camera and tflite plugin

For details: https://medium.com/@shaqian629/real-time-object-detection-in-flutter-b31c7ff9ef96 flutter_realtime_detection Real-time object detection i

Oct 12, 2022

Face detection app built with Flutter and Firebase ML Kit

Face detection app built with Flutter and Firebase ML Kit

Flutter Face Detection Flutter Face Detection with Firebase ML Kit and CustomPainter. Read the article on Medium Made with 😍 by Akora-IngDKB. Follow

Sep 29, 2022

Flutter form fields designed to take much of the burden of form-related coding off the programmer's back — masks, validations, keyboard type, etc.

Flutter form fields designed to take much of the burden of form-related coding off the programmer's back — masks, validations, keyboard type, etc.

well_formed Contents Overview Getting Started Demo application References Overview Well-Formed Widget Fields - Well-Formed - is a collection of Flutte

Nov 2, 2022

Flutter plugin for selecting images from the Android and iOS image library, taking new pictures with the camera, and edit them before using such as rotation, cropping, adding sticker/text/filters.

Flutter plugin for selecting images from the Android and iOS image library, taking new pictures with the camera, and edit them before using such as rotation, cropping, adding sticker/text/filters.

advance_image_picker Flutter plugin for selecting multiple images from the Android and iOS image library, taking new pictures with the camera, and edi

Dec 19, 2022

Color detection in images to capture presense of known objects.

Color detection in images to capture presense of known objects.

swatch Color detection in images to capture presence of known objects. Why? There is great object and face detection software out there, but sometimes

Dec 7, 2022

An app to pick, upload and display images from camera and gallery with size and extension constraints.

image_uploader A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started i

Mar 7, 2022

Interactive command line interface Couchbase Lite REPL utility built with the Dart

Interactive command line interface Couchbase Lite REPL utility built with the Dart

Couchbase Lite Dart CLI Interactive command line interface Couchbase Lite REPL utility built with the Dart programming language. This code uses the cb

Jul 20, 2022

Redditech: use the Reddit API in order to build a mobile app

Redditech: use the Reddit API in order to build a mobile app

Redditech Introduction Redditech is an IT project in which we had to use the Reddit API (https://www.reddit.com/dev/api/) in order to build a mobile a

Nov 15, 2022
Owner
Yousef Shaban
Mobile and Web Developer.
Yousef Shaban
Flutterbodydetection - A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmentation APIs for both static images and live camera stream.

body_detection A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmen

null 18 Dec 5, 2022
Flutter realtime object detection with Tensorflow Lite

Flutter realtime object detection with Tensorflow Lite Flutter realtime object d

null 0 Dec 25, 2021
Simple face recognition authentication (Sign up + Sign in) written in Flutter using Tensorflow Lite and Firebase ML vision library.

FaceNetAuthentication Simple face recognition authentication (Sign up + Sign in) written in Flutter using Tensorflow Lite and Google ML Kit library. S

Marcos Carlomagno 279 Jan 9, 2023
This is a flutter plugin to detect edges in a live camera, take the picture of detected edges object, crop it, and save.

edge_detection A flutter plugin to detect edges of objects, scan paper, detect corners, detect rectangles. It allows cropping of the detected object i

Sawan Kumar Bundelkhandi 180 Dec 28, 2022
Safemask-ai - AI that can Detect Masks Usage

AI Project to Detect Wearing Masks A Mobile App that able to detect if someone w

null 3 Feb 8, 2022
Mask Aware Face Attendance App built using Flutter

Face Attendance An App Made with Face SDK record.mp4 Before we get started ?? For now, Our app does support only Android platform (arm64). ?? You will

FaceOnLive 113 Dec 30, 2022
My flutter (android, ios) UI design examples 🎈 - user profile UIs, food order ui, splashscreen, mask widget usage, settings page ui

Flutter UI Design Examples ?? This repository contains the flutter ui designs I designed while learning. Doctor Appointment App UI Packages in use: fl

Aleyna Eser 23 Nov 14, 2022
A Flutter plugin to access TensorFlow Lite apis.

tensorflow_lite A Flutter plugin to access TensorFlow Lite apis. TensorFlow Lite is TensorFlow’s lightweight solution for mobile and embedded devices.

Kashif Minhaj 74 Nov 22, 2022
TensorFlow Lite Flutter Plugin

Overview TensorFlow Lite Flutter plugin provides a flexible and fast solution for accessing TensorFlow Lite interpreter and performing inference. The

Amish Garg 383 Jan 5, 2023
A full-fledged camera app built with Flutter using the camera package.

Flutter Camera Demo A full-fledged camera app built with Flutter using the camera package. You can even add custom features to this app and customize

NguyenHoangDuc 5 Nov 23, 2022