😌 Automatically detects and crops faces from batches of pictures.
Alternatives To Autocrop
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Smartcrop.js12,57460304 months ago11September 01, 202115mitJavaScript
Content aware image cropping
6 years ago1Java
A memory efficient Android image transformation library providing cropping above Face Detection (Face Centering) for Picasso.
5 years ago41otherC++
28 years ago1December 04, 20143apache-2.0Java
An Android library providing a useful widget class which automatically detects the presence of faces in the source image and crop it accordingly so to achieve the best visual result.
16 years ago1October 09, 20173mitSwift
:scissors: Crop faces, inside of your image, with iOS 11 Vision api.
9 years ago2apache-2.0Java
Android bitmap Face Cropper
10 months ago19January 25, 202210otherPython
:relieved: Automatically detects and crops faces from batches of pictures.
2 years ago5mitPython
A prize winning solution for DFDC challenge
6 years ago4Java
A memory efficient Android image transformation library providing cropping above Face Detection (Face Centering) for Glide.
24 years ago5October 22, 2018mitSwift
✂️ Detect and crop faces, barcodes and texts in image with iOS 11 Vision api.
Alternatives To Autocrop
Select To Compare

Alternative Project Comparisons


CI codecov Documentation PyPI version Downloads

Perfect for profile picture processing for your website or batch work for ID cards, autocrop will output images centered around the biggest face detected.



pip install autocrop


Autocrop can be used from the command line or directly from Python API.

From Python

Import the Cropper class, set some parameters (optional), and start cropping.

The crop method accepts filepaths or np.ndarray, and returns Numpy arrays. These are easily handled with PIL or Matplotlib.

from PIL import Image
from autocrop import Cropper

cropper = Cropper()

# Get a Numpy array of the cropped image
cropped_array = cropper.crop('portrait.png')

# Save the cropped image with PIL if a face was detected:
if cropped_array:
    cropped_image = Image.fromarray(cropped_array)'cropped.png')

Further examples and use cases are found in the accompanying Jupyter Notebook.

From the command line

usage: autocrop [-h] [-v] [--no-confirm] [-n] [-i INPUT] [-o OUTPUT] [-r REJECT] [-w WIDTH] [-H HEIGHT] [--facePercent FACEPERCENT]
                [-e EXTENSION]

Automatically crops faces from batches of pictures

  -h, --help            Show this help message and exit
  -v, --version         Show program's version number and exit
  --no-confirm, --skip-prompt
                        Bypass any confirmation prompts
  -n, --no-resize       Do not resize images to the specified width and height, but instead use the original image's pixels.
  -i, --input INPUT
                        Folder where images to crop are located. Default: current working directory
  -o, -p, --output, --path OUTPUT
                        Folder where cropped images will be moved to. Default: current working directory, meaning images are cropped in
  -r, --reject REJECT
                        Folder where images that could not be cropped will be moved to. Default: current working directory, meaning images
                        that are not cropped will be left in place.
  -w, --width WIDTH
                        Width of cropped files in px. Default=500
  -H, --height HEIGHT
                        Height of cropped files in px. Default=500
  --facePercent FACEPERCENT
                        Percentage of face to image height
  -e, --extension EXTENSION
                        Enter the image extension which to save at output


  • Crop every image in the pics folder, resize them to 400 px squares, and output them in the crop directory:
    • autocrop -i pics -o crop -w 400 -H 400.
    • Images where a face can't be detected will be left in crop.
  • Same as above, but output the images with undetected faces to the reject directory:
    • autocrop -i pics -o crop -r reject -w 400 -H 400.
  • Same as above but the image extension will be png:
    • autocrop -i pics -o crop -w 400 -H 400 -e png
  • Crop every image in the pics folder and output to the crop directory, but keep the original pixels from the images:
    • autocrop -i pics -o crop --no-resize

If no output folder is added, asks for confirmation and destructively crops images in-place.

Detecting faces from video files

You can use autocrop to detect faces in frames extracted from a video. A great way to perform the frame extraction step is with ffmpeg:

mkdir frames faces

# Extract one frame per second
ffmpeg -i input.mp4 -filter:v fps=fps=1/60 frames/ffmpeg_%0d.bmp

# Crop faces as jpg
autocrop -i frames -o faces -e jpg

Supported file types

The following file types are supported:

  • EPS files (.eps)
  • GIF files (.gif) (only the first frame of an animated GIF is used)
  • JPEG 2000 files (.j2k, .j2p, .jp2, .jpx)
  • JPEG files (.jpeg, .jpg, .jpe)
  • LabEye IM files (.im)
  • macOS ICNS files (.icns)
  • Microsoft Paint bitmap files (.msp)
  • PCX files (.pcx)
  • Portable Network Graphics (.png)
  • Portable Pixmap files (.pbm, .pgm, .ppm)
  • SGI files (.sgi)
  • SPIDER files (.spi)
  • TGA files (.tga)
  • TIFF files (.tif, .tiff)
  • WebP (.webp)
  • Windows bitmap files (.bmp, .dib)
  • Windows ICO files (.ico)
  • X bitmap files (.xbm)


Installing directly

In some cases, you may wish the package directly, instead of through PyPI:

cd ~
git clone
cd autocrop
pip install .


Development of a conda-forge package for the Anaconda Python distribution is currently stalled due to the complexity of setting up the workflow with OpenCV. Please leave feedback on issue #7 to see past attempts if you are insterested in helping out!


Best practice for your projects is of course to use virtual environments. At the very least, you will need to have pip installed.

Autocrop is currently being tested on:

  • Python 3.7 to 3.10
  • OS:
    • Linux
    • macOS
    • Windows

More Info

Check out:

Adapted from:


Although autocrop is essentially a CLI wrapper around a single OpenCV function, it is actively developed. It has active users throughout the world.

If you would like to contribute, please consult the contribution docs.

Popular Face Projects
Popular Crop Projects
Popular Machine Learning Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Computer Vision
Face Detection