Metadata-Version: 2.4
Name: face-analysis-kit
Version: 0.1.3
Summary: A package for analyzing faces in images to detect eye state, gaze direction, and facial expressions
Author: Ahmed Salim
License: MIT License
        
        Copyright (c) 2025 Ahmed Salim
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: homepath, https://github.com/ahmedsalim3/face-analysis.git
Project-URL: repository, https://github.com/ahmedsalim3/face-analysis.git
Keywords: facial-expressions,gaze-estimation,eye-tracking,deep-learning,pytorch,tensorflow
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: dlib>=19.24.6
Requires-Dist: face-detection>=1.0.5
Requires-Dist: facenet-pytorch==2.6.0
Requires-Dist: gdown>=5.2.0
Requires-Dist: matplotlib>=3.3.4
Requires-Dist: numpy>=1.19.5
Requires-Dist: opencv-python>=4.5.5
Requires-Dist: pandas>=1.1.5
Requires-Dist: pillow>=8.4.0
Requires-Dist: scipy>=1.5.4
Requires-Dist: tensorflow>=2.10
Requires-Dist: torch>=1.10.1
Requires-Dist: torchvision>=0.11.2
Provides-Extra: dev
Requires-Dist: ipython; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-coverage; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Dynamic: license-file

# Face Analysis Kit

A Python package for analyzing faces in images to detect eye state, gaze direction, and facial expressions.

|   |   |
|-------------|--------------|
| ![demo](./data/demo.png) |
|   |   |

## Features

- **Gaze Detection**: Determine gaze direction using ResNet models
- **Eye State Classification**: Detect whether eyes are open or closed
- **Emotion Recognition**: Identify facial expressions and emotions


## How to install:


### 1. Install from PyPI 

```sh
pip install face_analysis_kit
```

### 2. Build and install from source

1. Clone the repo

```sh
git clone https://github.com/ahmedsalim3/face-analysis.git
cd face-analysis
```

2. Create a virtual environment and install dependencies:

```sh
make install
```

This will:
- Install all dependencies using `uv`
- Set up pre-commit hooks for code quality

3. Activate the environment:

```sh
source .venv/bin/activate
```

__Optional: Install the package in editable mode `pip install -e .`__

## Usage Examples

### Command Line Interface

The package provides several command-line tools for analyzing faces in images:

1. Analyze a single image:
```sh
bash scripts/run_analysis.sh single input/test_1.png
```

2. Analyze all images in a folder:
```sh
bash scripts/run_analysis.sh folder input/
```

3. Select the best image from a folder:
```sh
bash scripts/run_analysis.sh best input/
```

Output will be saved to `output/<command>/` directory.

### Python API

#### Gaze Detection

```python
from face_analysis.gazes import Pipeline as GazesPipeline
from face_analysis.gazes import render as GazesRender

gaze_pipeline = GazesPipeline(
    arch='ResNet50',  # Options: "ResNet18", "ResNet34", "ResNet101", "ResNet152"
    detector="retinaface",  # Options: "mtcnn"
    device="cuda",  # or "cpu"
)

img_in = cv2.imread("input/test_1.png")
results = gaze_pipeline.step(img_in)
img_out = GazesRender(img_in, results)
```

|   |   |
|-------------|--------------|
| ![input](./input/test_2.jpg) | ![output](./output/folder/annotated/test_2_gazes.png) |
|   |   |

#### Eye State Detection

```python
from face_analysis.eyes import Pipeline as EyesPipeline
from face_analysis.eyes import render as eyes_render

eye_pipeline = EyesPipeline(
    detector="retinaface", # or "dlib"
    device="cpu", # or "cuda"
)

img_in = cv2.imread(img_path)
results = eye_pipeline.step(img_in)
img_out = eyes_render(img_in, results)
```

|   |   |
|-------------|--------------|
| ![input](./input/test_2.jpg) | ![output](./output/folder/annotated/test_2_eyes.png) |
|   |   |

#### Emotion Detection

```python
from face_analysis.emotions import Pipeline as EmotionsPipeline
from face_analysis.emotions import render as emotions_render

emotion_pipeline = EmotionsPipeline(
    detector= "retinaface", # or "mtcnn", or "cascade"
    device= "cpu",
)

img_in = cv2.imread(img_path)
results = emotion_pipeline.step(img_in)
img_out = emotions_render(img_in, results)
```

|   |   |
|-------------|--------------|
| ![input](./input/test_2.jpg) | ![output](./output/folder/annotated/test_2_emotions.png) |
|   |   |


## Repo Structure

```sh
project_root/
├── data/       
├── input/
├── output/
├── scripts/
├── face_analysis/                 
│
├── LICENSE.txt
├── pyproject.toml
├── README.md
├── requirements.txt
├── uv.lock
└── Makefile
```

## Contributing

Contributions are welcome! Please fork the repository, make your changes, and submit a pull request.

```sh
make install  # to setup environment and hooks
make test     # to run tests before submitting
```
