A memory efficient Android image transformation library providing cropping above Face Detection (Face Centering) for Picasso.
Switch branches/tags
Nothing to show
Clone or download
aryarohit07 Merge pull request #6 from pavlus/master
Updated Build Tools to 26.0.1, Play Services to 11.4.0, MIN_SDK to 14…
Latest commit b7d2ea4 Nov 26, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper initial commit Jul 19, 2016
images added example images Jul 24, 2016
library method description change Aug 13, 2016
.gitignore Update .gitignore Jul 19, 2016
CHANGELOG.md version 0.3.0 release Aug 13, 2016
README.md
build.gradle Updated Build Tools to 26.0.1, Play Services to 11.4.0, MIN_SDK to 14… Sep 28, 2017
gradle.properties Updated Build Tools to 26.0.1, Play Services to 11.4.0, MIN_SDK to 14… Sep 28, 2017
gradlew initial commit Jul 19, 2016
gradlew.bat initial commit Jul 19, 2016
settings.gradle initial commit Jul 19, 2016

README.md

Picasso face detection transformation

Download Android Arsenal

An Android image transformation library providing cropping above Face Detection (Face Centering) for Picasso

Are you using Glide? GlideFaceDetectionTransformation.

Are you using Fresco? FrescoFaceDetectionProcessor.

Results

Original Image

original image 1

Results after cropping

resulting image 1

Original Image

original image 2

Results after cropping

resulting image 2

Original Image

original image 3

Results after cropping

resulting image 3

Original Image

original image 4

Results after cropping

resulting image 4

You can read more on my Medium article.

How to use it?

STEP 1:

Grab via Gradle

repositories {
    jcenter()
}
dependencies {
    compile 'com.github.aryarohit07:picasso-facedetection-transformation:0.3.0'
}

Or via Maven

<dependency>
  <groupId>com.github.aryarohit07</groupId>
  <artifactId>picasso-facedetection-transformation</artifactId>
  <version>0.3.0</version>
</dependency>

STEP 2:

Initialize the detector (May be in onCreate() method)

PicassoFaceDetector.initialize(context);

STEP 3: Set picasso transform

Picasso
  .with(context)
  .load(url)
  .fit() // use fit() and centerInside() for making it memory efficient.
  .centerInside()
  .transform(new FaceCenterCrop(100, 100)) //in pixels. You can also use FaceCenterCrop(width, height, unit) to provide width, height in DP.
  .into(imageView);

STEP 4:

The face detector uses native resources in order to do detection. For this reason, it is necessary to release the detector instance once it is no longer needed (May be in onDestory() method)

PicassoFaceDetector.releaseDetector();

Note: If no face is detected, it will fallback to CENTER CROP.

Library dependencies:

com.google.android.gms:play-services-vision:9.4.0
com.squareup.picasso:picasso:2.5.2

If you liked it, please Star it.

TODO

  • Making it generic for any point.

Performance: Time taken to detect faces in the original image.

width height time taken(ms)
640 360 60-150
900 600 100-200
1280 720 250-350
1920 1080 350-400
2048 1536 500-550

License

Copyright 2016 Rohit Arya

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.