With Viola android face detection library, you can detect faces in a bitmap, crop faces using predefined algorithm and get additional information from the detected faces.

Overview

Viola

Download Platform API License

Viola android face detection library detects faces automatically from a bitmap, crop faces using the predefined algorithms, and provides supplementary information of the detected faces.

Features:
-> Prominent face detection
-> Multiple face detection
-> Automatic face crop
-> Face classification information
-> Age classification support

ScreenShot

Getting Started

Demo application

Download sample application sample_v_1.1.1

Compatibility

  • Minimum Android SDK : Viola 1.1.1 requires a minimum API level of 21.

Installation

Download the latest aar from JCenter or grab via

Gradle:

dependencies {
  implementation 'com.darwin.viola:still:1.1.1'
}

or Maven:

<dependency>
  <groupId>com.darwin.viola</groupId>
  <artifactId>still</artifactId>
  <version>1.1.1</version>
  <type>pom</type>
</dependency>

Usage

Kotlin

val viola = Viola(listener)
viola.addAgeClassificationPlugin(context) //optional, available via external dependency

viola.detectFace(bitmap)

private val listener: FaceDetectionListener = object : FaceDetectionListener {

        override fun onFaceDetected(result: Result) {}

        override fun onFaceDetectionFailed(error: FaceDetectionError, message: String) {}
}

with FaceOptions

val faceOption =
    FaceOptions.Builder()
               .enableProminentFaceDetection()
               .enableDebug()
               .build()
viola.detectFace(bitmap,faceOption)

Java

Viola viola = new Viola(listener);
viola.addAgeClassificationPlugin(context) //optional, available via external dependency

viola.detectFace(bitmap);

private final FaceDetectionListener listener = new FaceDetectionListener() {
        @Override
        public void onFaceDetected(@NotNull Result result) { }

        @Override
        public void onFaceDetectionFailed(@NotNull FaceDetectionError error, @NotNull String message) { }
};

with FaceOptions

FaceOptions faceOptions = new FaceOptions.Builder()
                .enableProminentFaceDetection()
                .enableDebug()
                .build();
viola.detectFace(bitmap,faceOptions);

Configure the face detector

Viola is currently extended with the following configurations. Instructions on how to use them in your own application are linked below.

FaceOptions Description Type Default
prominentFaceDetection Indicates whether to detect all faces, or to only detect the most prominent face boolean false
cropAlgorithm Extended option for controlling crop constraints CropAlgorithm CropAlgorithm.THREE_BY_FOUR
minFaceSize The minimum size percentage, relative to the image, of faces to detect int 15
ageClassification Indicate whether to enable age classification on detected face boolean false
debug enables debug log boolean false

CropAlgorithm.THREE_BY_FOUR : Performs face crop in three by four ratio

CropAlgorithm.SQUARE : Performs face crop in 1:1 ratio(useful when showing face in circular view)

CropAlgorithm.LEAST : Performs face crop with minimum padding(possibly reduce face overlap on multi face detection)

NOTE : add viola-age dependency to your application build.gradle file and viola.addAgeClassificationPlugin(this) to your viola sdk instance for ageClassification feature to work on detected face.

Face detection result

Viola provides the following values in Result class

Result Description Type
faceCount The number of faces croped int
facePortraits Contains list of cropped faces FacePortrait
face The cropped face bitmap Bitmap
smileProbability Giving a probability that the face is smiling Float
leftEyeOpenProbability Giving a probability that the face's left eye is open Float
rightEyeOpenProbability Giving a probability that the face's right eye is open Float
pixelBetweenEyes The number of pixels between the eyes Double
faceSizePercentage The size of face relative to the input image Float
facePose Provides rotation of face in X,Y,Z plane FacePose
ageRange Provides age range of detected face(s) String

Author

Darwin Francis - @darwinfrancis on GitHub, @darwin-francis on linkedin

Roadmap

-Add gender classification feature as plugin
-Add emotion classification feature as plugin
-Implement face detection and cropping from live camera preview.

Other works

Viola-Age age classification library for android.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT License

Copyright (c) 2020 Darwin Francis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...
An android application for creating a journal for subjects you studied and also you can set timer for break.
An android application for creating a journal for subjects you studied and also you can set timer for break.

Study Journal An android application for creating a journal for subjects you studied and also you can set timer for break between two consecutive subj

REST countries sample app that loads information from REST countries API V3 to show an approach to using some of the best practices in Android Development.
REST countries sample app that loads information from REST countries API V3 to show an approach to using some of the best practices in Android Development.

MAJORITY assignment solution in Kotlin via MVVM Repository Pattern. REST countries sample app that loads information from REST countries API V3 to sho

πŸ‘‹ A common toolkit (utils) βš’οΈ built to help you further reduce Kotlin boilerplate code and improve development efficiency. Do you think 'kotlin-stdlib' or 'android-ktx' is not sweet enough? You need this! 🍭

Toolkit [ 🚧 Work in progress ⛏ πŸ‘· πŸ”§οΈ 🚧 ] Snapshot version: repositories { maven("https://s01.oss.sonatype.org/content/repositories/snapshots") }

Sync chat messages and various information on Telegram and Minecraft

Sync chat messages and various information on Telegram and Minecraft

πŸ› οΈ The missing drawable toolbox for Android. Create drawables programmatically and get rid of the boring and always repeated drawable.xml files.
πŸ› οΈ The missing drawable toolbox for Android. Create drawables programmatically and get rid of the boring and always repeated drawable.xml files.

DrawableToolbox English | δΈ­ζ–‡ The missing DrawableToolbox for Android. Create drawables programmatically and get rid of the boring and always repeated

Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders
Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders

Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders.

A flutter plugin to scan stripe readers and connect to the them and get the payment methods.

stripe_terminal A flutter plugin to scan stripe readers and connect to the them and get the payment methods. Installation Android No Configuration nee

RickAndMortyApp - Rick and morty, app about characters information
RickAndMortyApp - Rick and morty, app about characters information

Rick And Morty App πŸ‡§πŸ‡· Aplicativo com tema do Rick and Morty, interatividade co

KaMP Kit by Touchlab is a collection of code and tools designed to get your mobile team started quickly with Kotlin Multiplatform.
KaMP Kit by Touchlab is a collection of code and tools designed to get your mobile team started quickly with Kotlin Multiplatform.

KaMP Kit Welcome to the KaMP Kit! About Goal The goal of the KaMP Kit is to facilitate your evaluation of Kotlin Multiplatform (aka KMP). It is a coll

Comments
  • Crash when using cropFaceByLeastAlgorithm - not frequently

    Crash when using cropFaceByLeastAlgorithm - not frequently

    Non-fatal Exception: java.lang.IllegalArgumentException: x must be >= 0 at android.graphics.Bitmap.checkXYSign(Bitmap.java:405) at android.graphics.Bitmap.createBitmap(Bitmap.java:800) at android.graphics.Bitmap.createBitmap(Bitmap.java:769) at com.darwin.viola.still.FaceAnalyser.cropFaceByLeastAlgorithm(FaceAnalyser.kt:246) at com.darwin.viola.still.FaceAnalyser.cropFace(FaceAnalyser.kt:125) at com.darwin.viola.still.FaceAnalyser.processFace(FaceAnalyser.kt:87) at com.darwin.viola.still.FaceAnalyser.analyseMultipleFaces(FaceAnalyser.kt:68) at com.darwin.viola.still.FaceAnalyser.analyzeFaces(FaceAnalyser.kt:32) at com.darwin.viola.still.detector.FaceDetectorProcessor.onSuccess(FaceDetectorProcessor.kt:63) at com.darwin.viola.still.detector.FaceDetectorProcessor.onSuccess(FaceDetectorProcessor.kt:33) at com.darwin.viola.still.detector.VisionProcessorBase$requestDetectInImage$1.invoke(VisionProcessorBase.kt:48) at com.darwin.viola.still.detector.VisionProcessorBase$requestDetectInImage$1.invoke(VisionProcessorBase.kt:31) at com.darwin.viola.still.detector.TaskExtensionsKt$sam$com_google_android_gms_tasks_OnSuccessListener$0.onSuccess(:2) at com.google.android.gms.tasks.zzm.run(com.google.android.gms:play-services-tasks@@17.2.1:1) at com.darwin.viola.still.detector.ScopedExecutor$execute$1.run(ScopedExecutor.kt:44) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6942) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

    bug 
    opened by bassil-altamimi 3
  • Crash after successful face detection

    Crash after successful face detection

    Exception happens while using it with live stream.

    Please find the details from logcat below.

    java.lang.IllegalArgumentException: width must be > 0 at android.graphics.Bitmap.checkWidthHeight(Bitmap.java:374) at android.graphics.Bitmap.createBitmap(Bitmap.java:665) at android.graphics.Bitmap.createBitmap(Bitmap.java:634) at com.darwin.viola.still.FaceAnalyser.cropFace(FaceAnalyser.kt:220) at com.darwin.viola.still.FaceAnalyser.processFace(FaceAnalyser.kt:96) at com.darwin.viola.still.FaceAnalyser.analyseMultipleFaces(FaceAnalyser.kt:70) at com.darwin.viola.still.FaceAnalyser.analyzeFaces(FaceAnalyser.kt:33) at com.darwin.viola.still.detector.FaceDetectorProcessor.onSuccess(FaceDetectorProcessor.kt:63) at com.darwin.viola.still.detector.FaceDetectorProcessor.onSuccess(FaceDetectorProcessor.kt:33) at com.darwin.viola.still.detector.VisionProcessorBase$requestDetectInImage$1.invoke(VisionProcessorBase.kt:48) at com.darwin.viola.still.detector.VisionProcessorBase$requestDetectInImage$1.invoke(VisionProcessorBase.kt:31) at com.darwin.viola.still.detector.TaskExtensionsKt$sam$com_google_android_gms_tasks_OnSuccessListener$0.onSuccess(TaskExtensions.kt) at com.google.android.gms.tasks.zzm.run(com.google.android.gms:play-services-tasks@@18.0.1:1) at com.darwin.viola.still.detector.ScopedExecutor$execute$1.run(ScopedExecutor.kt:44) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)

    bug 
    opened by george-aicenter 1
  • -> Fixed Crash when using cropFaceByLeastAlgorithm(ref:git-issue#9)

    -> Fixed Crash when using cropFaceByLeastAlgorithm(ref:git-issue#9)

    The bounding box from detected face may have negative coordinates, which results in invalid bitmap width and height. Fixed issue by resetting x and y position to zero if it is negative.

    opened by darwinfrancis 0
Releases(1.1.4)
Owner
Darwin Francis
Software Developer [Android, Flutter, Ktor]
Darwin Francis
[Android Library] Get easy access to device information super fast, real quick

DeviceInfo-Sample Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the d

Anitaa Murthy 193 Nov 20, 2022
Reusable login template to learn Kotlin & Android additional features

LogIn_Application reusable login template I started this project to learn Kotlin & Android additional features. This is LogIn Template App as part of

null 0 Dec 14, 2021
Android app to test various cryptography algorithm.

This android app shows how cryptographic algorithm works. You can encrypt or decrypt messages and try different algorithms. Powered by Bouncy Castle this app supports AES, Serpent, Blowfish and many more :)

null 3 Mar 21, 2022
On-device wake word detection powered by deep learning.

Porcupine Made in Vancouver, Canada by Picovoice Porcupine is a highly-accurate and lightweight wake word engine. It enables building always-listening

Picovoice 2.8k Dec 30, 2022
This library is a set of simple wrapper classes that are aimed to help you easily access android device information.

SysInfo Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the device info

Klejvi Kapaj 7 Dec 27, 2022
Simple Design for Kotlin bridge with Javascript. Also can get javascript console.log.

SDBridgeJava is here. If your h5 partner confused about how to deal with iOS and Android. This Demo maybe help. bilibili video introduction is here. Y

null 14 Dec 19, 2022
Example mod with Mixin to help you to get started with creating a mod with mixins.

ExampleMixinMod Example mod with Mixin to help you to get started with creating a mod with mixins. For usage of mixins, see here. Also, remember to tu

null 0 Dec 16, 2021
A set of highly-opinionated, batteries-included gradle plugins to get you started building delicious multi-module Kotlin projects

Sourdough Gradle What is Sourdough Gradle? Sourdough is a set of highly opinionated gradle plugins that aim to act as the starter for your Kotlin proj

Backbone 0 Oct 3, 2022
AarΓ³n Calixto Andrade 0 Dec 27, 2021