{"id":13585392,"url":"https://github.com/leblancfg/autocrop","last_synced_at":"2025-05-14T11:10:52.545Z","repository":{"id":41322215,"uuid":"45621518","full_name":"leblancfg/autocrop","owner":"leblancfg","description":":relieved: Automatically detects and crops faces from batches of pictures.","archived":false,"fork":false,"pushed_at":"2025-03-31T17:05:13.000Z","size":22232,"stargazers_count":647,"open_issues_count":16,"forks_count":122,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-05-13T05:09:05.886Z","etag":null,"topics":["autocrop","computer-vision","crop","face","face-detection","facedetect","opencv","pictures","python"],"latest_commit_sha":null,"homepage":"https://leblancfg.com/autocrop/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leblancfg.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-11-05T15:48:44.000Z","updated_at":"2025-04-25T14:54:20.000Z","dependencies_parsed_at":"2025-05-14T11:10:35.485Z","dependency_job_id":null,"html_url":"https://github.com/leblancfg/autocrop","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leblancfg%2Fautocrop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leblancfg%2Fautocrop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leblancfg%2Fautocrop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leblancfg%2Fautocrop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leblancfg","download_url":"https://codeload.github.com/leblancfg/autocrop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254129489,"owners_count":22019628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autocrop","computer-vision","crop","face","face-detection","facedetect","opencv","pictures","python"],"created_at":"2024-08-01T15:04:54.959Z","updated_at":"2025-05-14T11:10:47.533Z","avatar_url":"https://github.com/leblancfg.png","language":"Python","readme":"# autocrop\n\n[![CI](https://github.com/leblancfg/autocrop/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/leblancfg/autocrop/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/leblancfg/autocrop/branch/master/graph/badge.svg)](https://codecov.io/gh/leblancfg/autocrop) [![Documentation](https://img.shields.io/badge/docs-passing-success.svg)](https://leblancfg.com/autocrop) [![PyPI version](https://badge.fury.io/py/autocrop.svg)](https://badge.fury.io/py/autocrop) [![Downloads](https://pepy.tech/badge/autocrop)](https://pepy.tech/project/autocrop)\n\n\u003cp align=\"center\"\u003e\u003cimg title=\"obama_crop\" src=\"https://cloud.githubusercontent.com/assets/15659410/10975709/3e38de48-83b6-11e5-8885-d95da758ca17.png\"\u003e\u003c/p\u003e\n\nPerfect for profile picture processing for your website or batch work for ID cards, autocrop will output images centered around the biggest face detected.\n\n# Installation\nSimple!\n\n~~~sh\npip install autocrop\n~~~\n\n# Use\nAutocrop can be used [from the command line](#from-the-command-line) or directly [from Python API](#from-python).\n\n## From Python\nImport the `Cropper` class, set some parameters (optional), and start cropping.\n\nThe `crop` method accepts filepaths or `np.ndarray`, and returns Numpy arrays. These are easily handled with [PIL](https://pillow.readthedocs.io/) or [Matplotlib](https://matplotlib.org/).\n\n~~~python\nfrom PIL import Image\nfrom autocrop import Cropper\n\ncropper = Cropper()\n\n# Get a Numpy array of the cropped image\ncropped_array = cropper.crop('portrait.png')\n\n# Save the cropped image with PIL if a face was detected:\nif cropped_array is not None:\n    cropped_image = Image.fromarray(cropped_array)\n    cropped_image.save('cropped.png')\n~~~\n\nFurther examples and use cases are found in the [accompanying Jupyter Notebook](https://github.com/leblancfg/autocrop/blob/master/examples/visual_tests.ipynb).\n\n## From the command line\n\n    usage: autocrop [-h] [-v] [--no-confirm] [-n] [-i INPUT] [-o OUTPUT] [-r REJECT] [-w WIDTH] [-H HEIGHT] [--facePercent FACEPERCENT]\n                    [-e EXTENSION]\n\n    Automatically crops faces from batches of pictures\n\n    options:\n      -h, --help            Show this help message and exit\n      -v, --version         Show program's version number and exit\n      --no-confirm, --skip-prompt\n                            Bypass any confirmation prompts\n      -n, --no-resize       Do not resize images to the specified width and height, but instead use the original image's pixels.\n      -i, --input INPUT\n                            Folder where images to crop are located. Default: current working directory\n      -o, -p, --output, --path OUTPUT\n                            Folder where cropped images will be moved to. Default: current working directory, meaning images are cropped in\n                            place.\n      -r, --reject REJECT\n                            Folder where images that could not be cropped will be moved to. Default: current working directory, meaning images\n                            that are not cropped will be left in place.\n      -w, --width WIDTH\n                            Width of cropped files in px. Default=500\n      -H, --height HEIGHT\n                            Height of cropped files in px. Default=500\n      --facePercent FACEPERCENT\n                            Percentage of face to image height\n      -e, --extension EXTENSION\n                            Enter the image extension which to save at output\n\n### Examples\n\n* Crop every image in the `pics` folder, resize them to 400 px squares, and output them in the `crop` directory:\n\t- `autocrop -i pics -o crop -w 400 -H 400`.\n\t- Images where a face can't be detected will be left in `crop`.\n* Same as above, but output the images with undetected faces to the `reject` directory:\n\t- `autocrop -i pics -o crop -r reject -w 400 -H 400`.\n* Same as above but the image extension will be `png`:\n\t- `autocrop -i pics -o crop -w 400 -H 400 -e png`\n* Crop every image in the `pics` folder and output to the `crop` directory, but keep the original pixels from the images:\n    - `autocrop -i pics -o crop --no-resize`\n\t\nIf no output folder is added, asks for confirmation and destructively crops images in-place.\n\n### Detecting faces from video files\nYou can use autocrop to detect faces in frames extracted from a video. A great way to [perform the frame extraction step is with `ffmpeg`](https://ffmpeg.org/download.html):\n\n```sh\nmkdir frames faces\n\n# Extract one frame per second\nffmpeg -i input.mp4 -filter:v fps=fps=1/60 frames/ffmpeg_%0d.bmp\n\n# Crop faces as jpg\nautocrop -i frames -o faces -e jpg\n```\n\n\n# Supported file types\n\nThe following file types are supported:\n\n- EPS files (`.eps`)\n- GIF files (`.gif`) (only the first frame of an animated GIF is used)\n- JPEG 2000 files (`.j2k`, `.j2p`, `.jp2`, `.jpx`)\n- JPEG files (`.jpeg`, `.jpg`, `.jpe`)\n- LabEye IM files (`.im`)\n- macOS ICNS files (`.icns`)\n- Microsoft Paint bitmap files (`.msp`)\n- PCX files (`.pcx`)\n- Portable Network Graphics (`.png`)\n- Portable Pixmap files (`.pbm`, `.pgm`, `.ppm`)\n- SGI files (`.sgi`)\n- SPIDER files (`.spi`)\n- TGA files (`.tga`)\n- TIFF files (`.tif`, `.tiff`)\n- WebP (`.webp`)\n- Windows bitmap files (`.bmp`, `.dib`)\n- Windows ICO files (`.ico`)\n- X bitmap files (`.xbm`)\n\n# Misc\n### Installing directly\nIn some cases, you may wish the package directly, instead of through [PyPI](https://pypi.python.org/pypi):\n\n~~~\ncd ~\ngit clone https://github.com/leblancfg/autocrop\ncd autocrop\npip install .\n~~~\n\n### conda\nDevelopment of a `conda-forge` package for the [Anaconda Python distribution](https://www.anaconda.com/download/) is currently stalled due to the complexity of setting up the workflow with OpenCV. Please leave feedback on [issue #7](https://github.com/leblancfg/autocrop/issues/7) to see past attempts if you are insterested in helping out!\n\n### Requirements\nBest practice for your projects is of course to [use virtual environments](http://docs.python-guide.org/en/latest/dev/virtualenvs/). At the very least, you will need to [have pip installed](https://pip.pypa.io/en/stable/installing/).\n\nAutocrop is [currently being tested on](https://github.com/leblancfg/autocrop/actions/workflows/ci.yml):\n\n* Python 3.7 to 3.10\n* OS:\n    - Linux\n    - macOS\n    - Windows\n\n# More Info\nCheck out:\n\n* http://docs.opencv.org/master/d7/d8b/tutorial_py_face_detection.html#gsc.tab=0\n* http://docs.opencv.org/master/d5/daf/tutorial_py_histogram_equalization.html#gsc.tab=0\n\nAdapted from:\n\n* http://photo.stackexchange.com/questions/60411/how-can-i-batch-crop-based-on-face-location\n\n### Contributing\n\nAlthough autocrop is essentially a CLI wrapper around a single OpenCV function, it is actively developed. It has active users throughout the world.\n\nIf you would like to contribute, please consult the [contribution docs](CONTRIBUTING.md).\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleblancfg%2Fautocrop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleblancfg%2Fautocrop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleblancfg%2Fautocrop/lists"}