First test
Browse files- BD_photo/valdez.jpg +0 -0
- Dockerfile +11 -0
- main.py +56 -0
- requirements.txt +15 -0
BD_photo/valdez.jpg
ADDED
Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
WORKDIR /code
|
4 |
+
|
5 |
+
COPY ./requirements.txt /code/requirements.txt
|
6 |
+
|
7 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
8 |
+
|
9 |
+
COPY . .
|
10 |
+
|
11 |
+
CMD ["gunicorn", "-b", "0.0.0.0:7860", "main:app"]
|
main.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import os
|
3 |
+
import face_recognition
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
+
@app.route('/trouver_personnes', methods=['POST'])
|
8 |
+
def trouver_personnes():
|
9 |
+
# Vérifier si le fichier d'image est présent dans la requête
|
10 |
+
if 'image' not in request.files:
|
11 |
+
return jsonify({'message': 'Aucun fichier d\'image trouvé.'}), 400
|
12 |
+
|
13 |
+
image_a_comparer = request.files['image']
|
14 |
+
|
15 |
+
# Charger l'image à comparer
|
16 |
+
image = face_recognition.load_image_file(image_a_comparer)
|
17 |
+
encodage_image = face_recognition.face_encodings(image)
|
18 |
+
|
19 |
+
if len(encodage_image) == 0:
|
20 |
+
return jsonify({'message': 'Aucun visage détecté dans l\'image.'}), 400
|
21 |
+
|
22 |
+
encodage_image = encodage_image[0]
|
23 |
+
|
24 |
+
correspondances = []
|
25 |
+
|
26 |
+
# Parcourir les images dans le dossier identite_photo
|
27 |
+
for fichier in os.listdir('BD_photo'):
|
28 |
+
if fichier.endswith('.jpg') or fichier.endswith('.png'):
|
29 |
+
chemin_image = os.path.join('BD_photo', fichier)
|
30 |
+
image_base = face_recognition.load_image_file(chemin_image)
|
31 |
+
encodage_base = face_recognition.face_encodings(image_base)
|
32 |
+
|
33 |
+
if len(encodage_base) == 0:
|
34 |
+
continue
|
35 |
+
|
36 |
+
encodage_base = encodage_base[0]
|
37 |
+
|
38 |
+
# Comparer les encodages faciaux
|
39 |
+
correspondance = face_recognition.compare_faces([encodage_base], encodage_image)
|
40 |
+
|
41 |
+
if correspondance[0]:
|
42 |
+
nom_personne = os.path.splitext(fichier)[0]
|
43 |
+
taux_fiabilite = face_recognition.face_distance([encodage_base], encodage_image)[0]
|
44 |
+
# correspondances.append((nom_personne, taux_fiabilite))
|
45 |
+
correspondances.append(nom_personne)
|
46 |
+
|
47 |
+
# Trier les correspondances par ordre décroissant de taux de fiabilité
|
48 |
+
correspondances = sorted(correspondances, key=lambda x: x[1], reverse=True)
|
49 |
+
|
50 |
+
if len(correspondances) > 0:
|
51 |
+
return jsonify({'resultats': correspondances})
|
52 |
+
else:
|
53 |
+
return jsonify({'message': 'Aucune correspondance trouvée.'}), 404
|
54 |
+
|
55 |
+
if __name__ == '__main__':
|
56 |
+
app.run()
|
requirements.txt
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
blinker==1.6.2
|
2 |
+
click==8.1.7
|
3 |
+
cmake==3.21.4
|
4 |
+
colorama==0.4.6
|
5 |
+
dlib==19.24.2
|
6 |
+
face-recognition==1.3.0
|
7 |
+
face-recognition-models==0.3.0
|
8 |
+
Flask==2.3.3
|
9 |
+
itsdangerous==2.1.2
|
10 |
+
Jinja2==3.1.2
|
11 |
+
MarkupSafe==2.1.3
|
12 |
+
numpy==1.25.2
|
13 |
+
Pillow==10.0.0
|
14 |
+
Werkzeug==2.3.7
|
15 |
+
gunicorn
|