erstmal bild hochladet dann mapt biometrische data in .yml und detectiert gesichte , muss immer noch debuggt werden -- second commit

This commit is contained in:
El Haddoury Younes
2026-02-10 10:55:53 +01:00
parent 991ef9e360
commit 38eb314626
7 changed files with 114 additions and 1 deletions

10
bildPy/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,10 @@
# Default ignored files
/shelf/
/workspace.xml
# Ignored default folder with query files
/queries/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

1
bildPy/.idea/.name generated Normal file
View File

@@ -0,0 +1 @@
source.py

10
bildPy/.idea/bildPy.iml generated Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="Python 3.14" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
bildPy/.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.14" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.14" project-jdk-type="Python SDK" />
</project>

8
bildPy/.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/bildPy.iml" filepath="$PROJECT_DIR$/.idea/bildPy.iml" />
</modules>
</component>
</project>

View File

@@ -1,5 +1,76 @@
import cv2
import os
import numpy as np
img = cv2.imread("../data_raw/diddy/P_Diddy_2000.webp");
# da wir in src sind , so können wir zu andrem ordner kommen
RAW_DATA_PFAD = "../data_raw"
MODEL_PFAD = "../models"
MODEL_FILE = os.path.join(MODEL_PFAD, "trained_lbph.yml") # yml für biometrische Data
NAMES_FILE = os.path.join(MODEL_PFAD, "names.pkl") # für mapping the ids from bio data to real person
# gesicht detektor erstmal initializieren
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
#LBPH Recognizer initializieren
recognizer = cv2.face.LBPHFaceRecognizer_create()
# dir hersteller
def create_directory_if_not_exists(directory):
if not os.path.exists(directory):
os.makedirs(directory)
# trainiert model
def train_model():
print("\n-training is angefangen")
faces = []
ids = []
names_map = {}
current_id = 0
# überpruft ob data dir schon exestiert
if not os.path.exists(RAW_DATA_PFAD):
print(f"Error: Directory '{RAW_DATA_PFAD}' nicht gefunden.")
return
# geht durch jede ordner in data raw (e.g., diddy, kirk, etc.)
for person_name in os.listdir(RAW_DATA_PFAD):
person_path = os.path.join(RAW_DATA_PFAD, person_name)
# verpasst (skip) alles was nicht ordner ist so wie store.ds oder sowas (.txt....)
if not os.path.isdir(person_path):
continue
names_map[current_id] = person_name
print(f"Processing ID {current_id}: {person_name}")
# geht durch jedes Bild in der Ordner jeder Person
for image_name in os.listdir(person_path):
if image_name.startswith("."): continue # Skip unsichbare files die mit . starten
image_path = os.path.join(person_path, image_name)
# ladet das bild hoch dann convertiert zum Grayscale
img = cv2.imread(image_path)
if img is None: continue
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#detectiert gesichte
faces_rects = face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5)
for (x, y, w, h) in faces_rects:
# region von interest ist das gesicht selbst
roi = gray[y:y + w, x:x + h]
faces.append(roi)
ids.append(current_id)
current_id += 1
if len(faces) == 0:
print("No faces found. Please check your 'data_raw' folder.")
return