Code Monkey home page Code Monkey logo

face-crop's Introduction

FaceCrop ๐Ÿ“ธ

FaceCrop is a simple command-line tool that automates the cropping of images ๐Ÿ–ผ๏ธ based on face detection. It works by identifying the largest face (i.e., the face that's likely closest to the camera) in an image, adds a margin around it (which you can customize), and then crops the image to this area. This tool is ideal for quickly cropping batches of images for social media ๐Ÿ‘ฅ, user avatars ๐Ÿš€, or AI training datasets ๐Ÿ’ก.

Demo

Dependencies ๐Ÿ› ๏ธ

FaceCrop depends on the following Python libraries:

  • OpenCV
  • PIL
  • glob
  • argparse
  • os

Please make sure these are installed. You can install them using pip:

pip install opencv-python Pillow

Usage ๐Ÿ’ป

This tool can be used through the command line. Here is the general syntax:

python3 facecrop.py [input_directory] -o [output_directory] -s [desired_size] -r [margin_ratio]

Where:

  • [input_directory] is the path to the directory containing the images you want to crop.
  • [output_directory] (optional) is the path to the directory where you want to save the cropped images. If not provided, a new folder named "resized" will be created in the input directory.
  • [desired_size] (optional) is the desired size of the output images in pixels (default is 500).
  • [margin_ratio] (optional) is the margin around the face as a ratio of the face size (default is 0.2).

For example, the following command will crop all images in the "input_images" folder and save them to the "resized" folder. The size of the output images will be 500x500 pixels, and a 20% margin will be added around each detected face:

python3 facecrop.py input_images -o cropped_images -s 500 -r 0.2

Notes ๐Ÿ“

  • The face detection may not be perfect, especially with low-quality images, unusual lighting conditions, or uncommon face orientations. However, it should work well for typical photos ๐Ÿ“ท.
  • The tool will try to center the eyes and mouth of the face to the center of the image ๐Ÿ˜Š.
  • The cropping and resizing process may distort the aspect ratio of the original image.
  • Images without any detected faces will not be processed ๐Ÿšซ.
  • The tool works with most common image formats (JPG, PNG, etc.).

Future Features ๐Ÿ”ฎ

Here are a few enhancements we're thinking about for future versions of FaceCrop:

  1. Custom Aspect Ratios: Currently, the tool crops images to be squares (i.e., the width and height are the same). We plan to add an option to allow for custom aspect ratios. For example, you might want to crop images to be 500x700 pixels instead of just 500x500. This will provide greater flexibility for different use cases and requirements. ๐Ÿ”„

  2. Face Recognition: We could integrate face recognition functionality to allow users to crop images based on specific individuals. This would be particularly useful for user-specific albums or datasets. ๐Ÿ•ต๏ธโ€โ™€๏ธ

  3. Multiple Face Cropping: Currently, the tool crops images around the largest face it detects. An option to crop around each detected face and save as separate images would be helpful in situations with group photos. ๐Ÿ‘ช

  4. Command Line Interface (CLI) Improvements: Making the tool more interactive through the CLI would also be a good feature. For example, we could add progress bars for batch processes, previews of cropped images, and options to adjust settings on the fly. โŒจ๏ธ

  5. GUI Implementation: A GUI version of the tool could make it more accessible for users who aren't as comfortable with command-line interfaces. The GUI could provide real-time previews and adjustments. ๐Ÿ–ฅ๏ธ

  6. Machine Learning Improvements: Enhancing the face detection algorithm with machine learning could improve its accuracy, particularly with more difficult images. This could be an interesting area for development and collaboration. ๐Ÿค–

These are just a few of the possibilities. We welcome ideas and contributions from our users to make FaceCrop more useful! ๐ŸŒŸ

Contributing ๐Ÿค

Please feel free to fork this project, create a feature branch, and submit a pull request.

Contact ๐Ÿ“ฌ

If you have any questions, feel free to open an issue or submit a pull request.

face-crop's People

Contributors

sanlega avatar

Watchers

Kostas Georgiou avatar  avatar

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.