Coder Social home page Coder Social logo

aafacedetection's Introduction

AAFaceDetection: Visage

Prototyping-Library providing easy access to iOS face detection features through NSNotification.

Introduction

Although face-recognition was first introduced to the platform by Apple in iOS 5, we haven't seen much creative use of this quite interesting feature, especially on live video. This technology is especially interesting for prototyping experimental user-interfaces that make use of the user's emotion (smiling, blinking or winking) or detect the user's attention (whether he is looking at the screen or not). That's why I wanted to make it as easy as possible to prototype those interactions with a simple model based on NSNotification whenever the status of the user's face changes. All the main features of Apples CIDetector(ofType: CIDetectorTypeFace…) are implemented and can be easily accessed.

Please keep in mind that this is meant as a tool for designers using Swift to prototype. This isn't meant for production environments but for quick experimentation with interactions. I've been doing a few private experiments with it as well as one big project for university, but it's still a work in progress.

Usage

To start using "AAFaceDetection/Visage" just drag the "Visage.swift" file into your project folder.

Visage is instantiated by passing a camera-position and an optimization setting for performance like this:

let visage = Visage(cameraPosition: Visage.CameraDevice.FaceTimeCamera, optimizeFor: Visage.DetectorAccuracy.HigherPerformance)

For cameraPosition the possible options are:

  • .ISightCamera, which uses the back-facing camera of the iPhone or iPad.
  • .FaceTimeCamera, which uses the front-facing camera of the iPhone or iPad.

For optimizeFor the possible options are:

  • .HigherPerformance, which sets CIDetectorAccuracy to CIDetectorAccuracyHigh.
  • .BatteryLife, which sets CIDetectorAccuracy to CIDetectorAccuracyLow. (also recommended on older devices)

As I said earlier Visage is based on sending NSNotifications as this is one of the easiest to grasp principles (at least it was for me) for beginners and it basically just works. You can subscribe to a number of events:

  • visageNoFaceDetectedNotification fires whenever there has been no face detected.
  • visageFaceDetectedNotification fires whenever there has been a face detected. 😐
  • visageHasSmileNotification fires when the user is smiling. 😃
  • visageHasNoSmileNotification fires when the user stopped smiling.
  • visageBlinkingNotification fires when the user is blinking. (2 eyes closed at once)
  • visageNotBlinkingNotification fires when the user stopped blinking. (at least one eye opened)
  • visageWinkingNotification fires when the user is winking. (1 eye closed) 😉
  • visageNotWinkingNotification fires when the user stopped winking. (2 eyes opened or closed)
  • visageLeftEyeClosedNotification fires when the user closed the left eye.
  • visageLeftEyeOpenNotification fires when the user opened the left eye.
  • visageRightEyeClosedNotification fires when the user closed the right eye.
  • visageRightEyeOpenNotification fires when the user opened the right eye.

You can subscribe to these events by using one of the provided methods NSNotificationCenter.defaultCenter().addObsever*. In the example I'm using the completionBlock but you can use any of the three provided functions and simply pass a selector.

By default these notifications are fired only when the status changes. There is however the option to receive a continuous stream of notifications, which may be handy for some purposes, which can be activated by setting visage!.onlyFireNotificatonOnStatusChange = false. Keep in mind that this setting will likely decrease performance.

Visage provides a bunch of properties:

  • faceDetected : Bool? whether there has been a face detected.
  • faceBounds : CGRect? the position and size of the face in pixels on screen.
  • faceAngle : CGFloat? the absolute angle of the face in radians.
  • faceAngleDifference : CGFloat? the relative angle of the the face (to the previous one) in radians.
  • leftEyePosition : CGPoint? the position of the left eye on screen.
  • rightEyePosition : CGPoint? the position of the right eye on screen.
  • mouthPosition : CGPoint? the position of the mouth on screen.
  • hasSmile : Bool? whether there has been a smile detected.
  • isWinking : Bool? whether there has been a wink detected.
  • isBlinking : Bool? whether there has been a blink detected.
  • leftEyeClosed : Bool? whether the left eye is closed or not.
  • rightEyeClosed : Bool?whether the right eye is closed or not.

Visage also provides a previewView of the camera-image as this is something you might want. Just add it to your view hierarchy like this: self.view.addSubview(visage!.visageCameraView).

Example Project

The very simple example project hopefully demonstrates the gist of using "AAFaceDetection/Visage" and is thoroughly commented. If you have any questions don't hesitate contacting me @aaronabentheuer.

screencast

License

Released under the MIT License. Copyright © 2015 Aaron Abentheuer.

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.

aafacedetection's People

Contributors

aaronabentheuer avatar bryant1410 avatar zaidsa avatar

Watchers

 avatar  avatar

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.