Skip to content

pacobaco/FaceFlow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

# FaceFlow

**Facial Recognition Workflow Engine for Facial Expression & Emotive Processing**

FaceFlow is a lightweight, modular Python framework that lets you build, run, and manage custom pipelines for face detection, landmark extraction, emotion recognition, and more. It supports images and real-time video, with first-class integration for **MediaPipe** (fast detection/landmarks) and **DeepFace** (state-of-the-art emotion, age, gender, and identity analysis).

---

## ✨ Features

- **Workflow Engine**: Chain reusable steps (linear or easily extendable to DAGs)
- **Multi-Face Support**: Handles multiple faces per frame/image
- **Emotive Processing**: Dominant emotions + confidence scores (`happy`, `sad`, `angry`, `surprised`, `neutral`, `fear`, `disgust`)
- **Backends**:
  - MediaPipe (real-time face detection + 468 landmarks)
  - DeepFace (emotion + facial attribute analysis, supports MediaPipe detector)
- **Input Flexibility**: File paths, NumPy arrays (OpenCV), webcam, or uploaded files
- **API Ready**: FastAPI endpoints for easy integration
- **Extensible**: Add custom steps (e.g., Py-Feat for Action Units, your own ML models, identity DB)
- **Production Friendly**: Logging, error handling, video support

---

## 📦 Installation

```bash
# Clone or download the project
git clone <your-repo-url>
cd faceflow

# Install dependencies
pip install -r requirements.txt

# Optional: Advanced expression analysis
pip install py-feat

Core Dependencies (in requirements.txt):

  • opencv-python
  • mediapipe
  • deepface
  • fastapi, uvicorn
  • numpy

🚀 Quick Start

1. Basic Image Analysis (Python)

import cv2
from faceflow.core.engine import FaceFlowEngine
from faceflow.core.workflow import Workflow
from faceflow.steps.loader import LoadImageStep
from faceflow.steps.detection import MediaPipeFaceDetector
from faceflow.steps.emotion import DeepFaceEmotionAnalyzer

# Create and register workflow
engine = FaceFlowEngine()
wf = (Workflow("basic_emotion")
      .add_step(LoadImageStep())
      .add_step(MediaPipeFaceDetector())
      .add_step(DeepFaceEmotionAnalyzer(detector_backend="mediapipe")))

engine.register_workflow(wf)

# Run
image = cv2.imread("tests/sample_face.jpg")
result = engine.execute("basic_emotion", {"image": image})

print(f"Detected {result.get('num_faces')} face(s)")
for emotion in result.get("emotions", []):
    print(f"Dominant emotion: {emotion['dominant_emotion']}")

2. Start the API Server

uvicorn faceflow.api.main:app --reload

Test with curl or Postman:

curl -X POST "http://127.0.0.1:8000/analyze" \
  -F "file=@sample_face.jpg" \
  -F "workflow=basic_emotion"

📁 Project Structure

faceflow/
├── faceflow/
│   ├── core/          # Engine, Workflow, Step base
│   ├── steps/         # Reusable pipeline steps
│   ├── utils/
│   ├── api/           # FastAPI endpoints
│   └── cli.py
├── examples/          # Usage demos
├── tests/
├── requirements.txt
└── README.md

Key steps available:

  • LoadImageStep
  • MediaPipeFaceDetector
  • MediaPipeFaceMesh (landmarks)
  • DeepFaceEmotionAnalyzer

🎥 Video / Real-Time Processing

See examples/video_emotion_workflow.py for webcam or video file processing with frame-by-frame analysis and on-screen overlays.


🛠 Extending FaceFlow

Add a Custom Step

from faceflow.core.step import Step

class MyCustomStep(Step):
    def process(self, data):
        # Your logic here (e.g., head pose, spoof detection)
        return data

Register New Workflow

custom_wf = Workflow("my_workflow").add_step(...)...
engine.register_workflow(custom_wf)

📊 Supported Emotions (via DeepFace)

  • angry
  • fear
  • neutral
  • sad
  • disgust
  • happy
  • surprise

🤝 Contributing

  1. Fork the repo
  2. Create a feature branch
  3. Add tests for new steps
  4. Submit a Pull Request

We welcome new backends, visualization steps, and documentation improvements.


📄 License

MIT License – see file.


🙏 Acknowledgments

  • MediaPipe by Google
  • DeepFace – Lightweight face recognition & attribute analysis
  • OpenCV community

Made with ❤️ for computer vision & affective computing enthusiasts.

Questions? Open an issue or reach out!

Copy the content above into `README.md` at the root of your project. It is professional, comprehensive, and ready for GitHub or internal use. Let me know if you want a version with badges, screenshots, or more sections!

About

Facial recognition workflow engine focused on expression & emotive processing.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages