Giter Club home page Giter Club logo

faceaware's Introduction

FaceAware

Sometimes the aspect ratios of images we need to work with don't quite fit within the confines of our UIImageViews.

In most cases we can use AspectFill to fit the image to the bounds of a UIImageView without stretching or leaving whitespace, however when it comes to photos of people, it's quite often to have the faces cropped out if they're not perfectly centered.

This is where FaceAware comes in. It will analyse an image either through UIImageView's image property, or one you set using one of the built in functions and focus in on any faces it can find within.

The most common use for FaceAware is with avatars.

With FaceAware your users will no longer have to crop and adjust their profile pictures.

Based on these two older projects:

Both of which don't seem to be maintained anymore.

Requirements

  • Swift 5.1
  • iOS 8.0+
  • Xcode 11

Installation

Manual

Simply drag UIImageView+FaceAware.swift into your project.

Carthage

  • Add github "BeauNouvelle/FaceAware" to your Cartfile

More information on installing and setting up Carthage can be found here: https://github.com/Carthage/Carthage

Cocoapods

  • Add pod 'FaceAware' to your pod file.
  • Add import FaceAware to the top of your files where you wish to use it.

Usage

There are a few ways to get your image views focussing in on faces within images.

Interface Builder

This is the easiest method and doesn't require writing any code. The extension makes use of @IBDesignable and @IBInspectable so you can turn on focusOnFaces from within IB. However you won't actually see the extension working until you run your project.

Code

You can set focusOnFaces to true.

someImageView.focusOnFaces = true

Be sure to set this after setting your image. If no image is present when this is called, there will be no faces to focus on.


Alternatively you can use:

someImageView.set(image: myImage, focusOnFaces: true)

Which elimates the worry of not having an image previously set.


You can also recieve a callback for when face detection and any image adjustments have been completed by passing in a closure to the didFocusOnFaces property.

someImageView.didFocusOnFaces = {
     print("Did finish focussing")
}

Debugging

FaceAware now features a debug mode which draws red squares around any detected faces within an image. To enable you can set the debug property to true.

someImageView.debug = true

You can also set this flag within interface builder.

More help? Questions?

Reach out to me on Twitter @beaunouvelle Also, if you're using this in your project and you like it, please let me know so I can continue working on it!

Future Plans

  • Add an option to only focus on largest/closest face in photo.

faceaware's People

Contributors

algrid avatar ashu avatar beaunouvelle avatar jk2k avatar omaralbeik avatar s2ler avatar t-pham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

faceaware's Issues

Pods’ Swift 2.3 version

Hi,

First of all — cool library, thanks for sharing it!

I’d like to use the Swift 2.3 version, what version should I refer to on my cocoa pods?

Thanks!

Doesn't handle frame changes

If the frame changes aspect ratio, the visible image layer isn't recomputed with the new aspect ratio.

This is easiest to see on with a full-screen view that handles rotation on a long thin device like an iPhone 5, when you rotate from portrait to landscape the preserved pixels from the original image should be different between the two modes.

Face processing is occurring multiple times.

  1. When focusOnFaces is set.
  2. When layoutSubviews is called.

Face detection is already quite expensive on resources, and to double up on that just isn't acceptable, especially with the number of apps out there now using this library.

Memory issue

WeakSelf(imageView) [imageView sd_setImageWithURL:[NSURL URLWithString:url] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { weakimageView.image = image; weakimageView.focusOnFaces = YES; }];

When I scroll the TableView, This code will be performed.( I used SDWebImage to set ImageView image and Then focusOnFaces )
And the memory report The memory used so high.

What can do to reduce memory ?

Getting a strange "Blinking"

Hi @BeauNouvelle

Any idea why would I see the following issue: when focusOnFaces is set On I get a strange issue where the image is being seen for a brief moment, then it disappears and the re-apears. It all happens very fast but the issue is noticeable and happens every time.

Any thoughts maybe?

Cocoapods support

Hey there,

First of all, thanks for making this open source! I wanted to ask if you're planning to make this available via Cocoapods?

Thanks

Fix Xcode 8 / iOS 10 Requirement

I wanted to test your library out to see if it would work for an app I am developing, but it looks like you built the entire example app in Xcode 8 Beta using iOS 10. You really shouldn't release public libraries under Betas. Would love to see this re-built in the current release version of Xcode.

Cheers!

Request: Zoom to face

Would be cool to also zoom to the face so that the head+neck+shoulders is visible. Great for Avatars.

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.