Perfect for profile picture processing for your website or batch work for ID cards, autocrop will output images centered around the biggest face detected.
From the command line:
usage: autocrop [-h] [-p PATH] [-w WIDTH] [-H HEIGHT] [-v]
optional arguments:
-h, --help show this help message and exit
-p PATH, --path PATH folder where images to crop are located. Default:
photos/
-w WIDTH, --width WIDTH
width of cropped files in px. Default: 500
-H HEIGHT, --height HEIGHT
height of cropped files in px. Default: 500
-v, --version show program's version number and exit
- Example:
autocrop -p pics -w 400 -H 400
.
The previous command will:
- Create a copy of all images found in the top level of
pics
topics/bkp
, - Crop to 400x400 pixels all images found in the top level of
pics
topics/crop
.
Images where a face can't be detected will be left in pics
.
Simple! In your command line, type:
pip install autocrop
Autocrop uses OpenCV to perform face detection, which is installed through binary wheels. If you already have OpenCV 3+ installed, you may wish to uninstall the additional OpenCV installation: pip uninstall opencv-python
.
In some cases, you may wish the package directly, instead of through PyPI:
cd ~
git clone https://github.com/leblancfg/autocrop
cd autocrop
pip install .
Development of a conda-forge
package for the Anaconda Python distribution is also currently slated for development. Please leave feedback on issue #7 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:
- 2.7
- 3.4
- 3.5
- 3.6
- OS:
- Linux
- macOS
- Windows
Check out:
- http://docs.opencv.org/master/d7/d8b/tutorial_py_face_detection.html#gsc.tab=0
- http://docs.opencv.org/master/d5/daf/tutorial_py_histogram_equalization.html#gsc.tab=0
Adapted from:
Pull requests are always welcome. I don't have much time to put into this project as "I've already scratched my own itch", but realize it can be useful to larger community. If you'd like to contribute to the codebase:
- Fork the repository on GitHub and clone it on your local machine,
git clone https://github.com/your_username/autocrop
- Make a branch off of master and make the changes you have in mind,
git checkout -b issue-007
- Run the tests with
pytest
in the root-level directory to make sure you didn't mistakenly break anything else. - Commit your changes: one item per commit if possible,
git commit -a -m 'fixed issue 007'
- Once development is done, always run
flake8 .
to check your coding style, as PEP8 is enforced and will fail your CI otherwise. - Push the modified codebase back to your forked version on Github,
git push origin issue-007
- On GitHub, submit a Pull Request to the master branch.
If you'd like to have a development environment for autocrop, you should create a virtualenv and then do pip install -e .
from within the directory.