Skip to content

a-tabaza/center_crop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Face Cropper

Stripped down functionality from Face Crop Plus using AMD's RetinaFace ONNX with no PyTorch dependancy, a 1.7 MB model artifact and a single file of code for inference.

Why

What I need: square image of one face from image of one face that is not square.

What I don't need: 7GB venv with CUDA PyTorch dependencies.

How

Detects bbox of a face (one face) in the picture (using RetinaFace and ONNX for inference) then crops a square around it with the face being in the center (cv2 slicing).

Setup

Local

uv venv
uv pip install -r requirements.txt
. .venv/bin/activate

Docker (API)

Build

docker build -t cropper .
docker run -d -p 8080:8080 cropper:latest

Pull

docker pull ghcr.io/a-tabaza/center_crop:main
docker run -d -p 8080:8080 ghcr.io/a-tabaza/center_crop:main

Go to localhost:8080/docs for SwaggerUI

Usage

CLI

python src/crop.py -i input.jpg -o output.jpg

API

Multiple images (result in .zip file)

curl -X 'POST' \
  'http://localhost:8080/crop/' \
  -H 'accept: image/jpeg' \
  -H 'Content-Type: multipart/form-data' \
  -F 'files=@4.jpg;type=image/jpeg' \
  -F 'files=@3.jpeg;type=image/jpeg' \
  -F 'files=@2.jpg;type=image/jpeg' \
  -F 'files=@1.jpg;type=image/jpeg'

One image (result back as jpg)

curl -X 'POST' \
  'http://localhost:8080/crop/' \
  -H 'accept: image/jpeg' \
  -H 'Content-Type: multipart/form-data' \
  -F 'files=@1.jpg;type=image/jpeg' \

Examples

Contributing

No. This isn't for you, it's to save my time, if it helps, I'm glad, if it doesn't, fork and adapt it.

About

Crop image of one face into a square if it's not a square, no PyTorch

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors