Spaces:
Sleeping
Sleeping
Commit ·
36f7f98
1
Parent(s): f3ac5c9
build(docker): update docker configuration and dependencies
Browse files- .dockerignore +17 -0
- .gitignore +42 -0
- Dockerfile +3 -1
- README.md +53 -5
- requirements.txt +3 -10
- test_app.py +41 -0
.dockerignore
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.git
|
| 2 |
+
.github
|
| 3 |
+
__pycache__
|
| 4 |
+
*.pyc
|
| 5 |
+
*.pyo
|
| 6 |
+
*.pyd
|
| 7 |
+
.db
|
| 8 |
+
.sqlite3
|
| 9 |
+
.env
|
| 10 |
+
.venv
|
| 11 |
+
venv
|
| 12 |
+
dataset
|
| 13 |
+
trainer
|
| 14 |
+
output.jpg
|
| 15 |
+
README.md
|
| 16 |
+
Dockerfile
|
| 17 |
+
.dockerignore
|
.gitignore
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
*.so
|
| 6 |
+
.Python
|
| 7 |
+
env/
|
| 8 |
+
build/
|
| 9 |
+
develop-eggs/
|
| 10 |
+
dist/
|
| 11 |
+
downloads/
|
| 12 |
+
eggs/
|
| 13 |
+
.eggs/
|
| 14 |
+
lib/
|
| 15 |
+
lib64/
|
| 16 |
+
parts/
|
| 17 |
+
sdist/
|
| 18 |
+
var/
|
| 19 |
+
wheels/
|
| 20 |
+
*.egg-info/
|
| 21 |
+
.installed.cfg
|
| 22 |
+
*.egg
|
| 23 |
+
|
| 24 |
+
# Virtual environments
|
| 25 |
+
venv/
|
| 26 |
+
.venv/
|
| 27 |
+
ENV/
|
| 28 |
+
|
| 29 |
+
# Local configuration
|
| 30 |
+
.env
|
| 31 |
+
.env.example
|
| 32 |
+
|
| 33 |
+
# Project specific
|
| 34 |
+
dataset/
|
| 35 |
+
trainer/
|
| 36 |
+
output.jpg
|
| 37 |
+
|
| 38 |
+
# IDEs
|
| 39 |
+
.vscode/
|
| 40 |
+
.idea/
|
| 41 |
+
*.swp
|
| 42 |
+
*.swo
|
Dockerfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
FROM python:3.
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
@@ -6,6 +6,8 @@ RUN apt-get update && apt-get install -y \
|
|
| 6 |
build-essential \
|
| 7 |
curl \
|
| 8 |
git \
|
|
|
|
|
|
|
| 9 |
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
COPY requirements.txt ./
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
|
|
| 6 |
build-essential \
|
| 7 |
curl \
|
| 8 |
git \
|
| 9 |
+
libgl1 \
|
| 10 |
+
libglib2.0-0 \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
COPY requirements.txt ./
|
README.md
CHANGED
|
@@ -7,13 +7,61 @@ sdk: docker
|
|
| 7 |
app_port: 8501
|
| 8 |
tags:
|
| 9 |
- streamlit
|
|
|
|
|
|
|
| 10 |
pinned: false
|
| 11 |
-
short_description: Streamlit
|
| 12 |
---
|
| 13 |
|
| 14 |
-
#
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
app_port: 8501
|
| 8 |
tags:
|
| 9 |
- streamlit
|
| 10 |
+
- facial-recognition
|
| 11 |
+
- opencv
|
| 12 |
pinned: false
|
| 13 |
+
short_description: Sistema de Reconhecimento Facial com Streamlit e OpenCV
|
| 14 |
---
|
| 15 |
|
| 16 |
+
# Sistema de Reconhecimento Facial
|
| 17 |
|
| 18 |
+
Este projeto é uma aplicação web interativa construída com Streamlit e OpenCV para coleta de dados, treinamento e reconhecimento facial.
|
| 19 |
|
| 20 |
+
## Funcionalidades
|
| 21 |
+
|
| 22 |
+
1. **Coleta de Dados:** Faça upload de fotos de uma pessoa e o sistema irá detectar e recortar as faces para criar um dataset.
|
| 23 |
+
2. **Treinamento:** Treine um modelo de reconhecimento (LBPH ou CNN opcional) usando as imagens coletadas.
|
| 24 |
+
3. **Reconhecimento:** Carregue uma imagem para identificar as pessoas cadastradas.
|
| 25 |
+
|
| 26 |
+
## Como Executar
|
| 27 |
+
|
| 28 |
+
### Usando Docker (Recomendado)
|
| 29 |
+
|
| 30 |
+
1. Construa a imagem:
|
| 31 |
+
```bash
|
| 32 |
+
docker build -t facial-recognition .
|
| 33 |
+
```
|
| 34 |
+
2. Execute o container:
|
| 35 |
+
```bash
|
| 36 |
+
docker run -p 8501:8501 facial-recognition
|
| 37 |
+
```
|
| 38 |
+
3. Acesse `http://localhost:8501` no seu navegador.
|
| 39 |
+
|
| 40 |
+
### Localmente
|
| 41 |
+
|
| 42 |
+
1. Instale as dependências:
|
| 43 |
+
```bash
|
| 44 |
+
pip install -r requirements.txt
|
| 45 |
+
```
|
| 46 |
+
2. Execute o app:
|
| 47 |
+
```bash
|
| 48 |
+
streamlit run streamlit_app.py
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
## Estrutura do Projeto
|
| 52 |
+
|
| 53 |
+
- `streamlit_app.py`: Interface web principal.
|
| 54 |
+
- `face_recognition_app.py`: Lógica de processamento de imagem e treinamento.
|
| 55 |
+
- `dataset/`: Armazena as faces recortadas para treino.
|
| 56 |
+
- `trainer/`: Armazena os modelos treinados.
|
| 57 |
+
- `Dockerfile`: Configuração para containerização.
|
| 58 |
+
- `requirements.txt`: Dependências do projeto.
|
| 59 |
+
|
| 60 |
+
## Requisitos
|
| 61 |
+
|
| 62 |
+
- Python 3.11
|
| 63 |
+
- OpenCV (contrib)
|
| 64 |
+
- Streamlit
|
| 65 |
+
- NumPy
|
| 66 |
+
- Pillow
|
| 67 |
+
- MTCNN
|
requirements.txt
CHANGED
|
@@ -1,12 +1,5 @@
|
|
| 1 |
-
|
| 2 |
-
matplotlib==3.8.4
|
| 3 |
-
pandas==2.2.2
|
| 4 |
-
torch==2.8.0
|
| 5 |
-
torchvision==0.23.0
|
| 6 |
-
tqdm==4.66.4
|
| 7 |
-
|
| 8 |
-
# Adicionados para o projeto de reconhecimento facial
|
| 9 |
opencv-contrib-python==4.8.0.76
|
| 10 |
numpy==1.26.4
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 1 |
+
streamlit==1.32.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
opencv-contrib-python==4.8.0.76
|
| 3 |
numpy==1.26.4
|
| 4 |
+
pillow==10.2.0
|
| 5 |
+
mtcnn==0.1.1
|
test_app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Nota: Estes testes requerem Python 3.11 e as dependências do requirements.txt instaladas.
|
| 2 |
+
import unittest
|
| 3 |
+
import numpy as np
|
| 4 |
+
import cv2
|
| 5 |
+
import os
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from face_recognition_app import ensure_dirs, detect_faces, is_image_file
|
| 8 |
+
|
| 9 |
+
class TestFacialRecognition(unittest.TestCase):
|
| 10 |
+
|
| 11 |
+
def setUp(self):
|
| 12 |
+
ensure_dirs()
|
| 13 |
+
# Criar uma imagem de teste (preta com um quadrado branco simulando uma face)
|
| 14 |
+
self.test_img = np.zeros((400, 400, 3), dtype=np.uint8)
|
| 15 |
+
self.test_img_path = 'test_image.jpg'
|
| 16 |
+
cv2.imwrite(self.test_img_path, self.test_img)
|
| 17 |
+
|
| 18 |
+
def tearDown(self):
|
| 19 |
+
if os.path.exists(self.test_img_path):
|
| 20 |
+
os.remove(self.test_img_path)
|
| 21 |
+
if os.path.exists('output.jpg'):
|
| 22 |
+
os.remove('output.jpg')
|
| 23 |
+
|
| 24 |
+
def test_ensure_dirs(self):
|
| 25 |
+
ensure_dirs()
|
| 26 |
+
self.assertTrue(Path('dataset').exists())
|
| 27 |
+
self.assertTrue(Path('trainer').exists())
|
| 28 |
+
|
| 29 |
+
def test_is_image_file(self):
|
| 30 |
+
self.assertTrue(is_image_file('test.jpg'))
|
| 31 |
+
self.assertTrue(is_image_file('test.PNG'))
|
| 32 |
+
self.assertFalse(is_image_file('test.txt'))
|
| 33 |
+
self.assertFalse(is_image_file('test.pdf'))
|
| 34 |
+
|
| 35 |
+
def test_detect_faces_empty_image(self):
|
| 36 |
+
# Uma imagem preta não deve detectar faces (usando Haar Cascade padrão)
|
| 37 |
+
faces = detect_faces(self.test_img)
|
| 38 |
+
self.assertEqual(len(faces), 0)
|
| 39 |
+
|
| 40 |
+
if __name__ == '__main__':
|
| 41 |
+
unittest.main()
|