From 38eb3146263622dce4b8510f0aee4e3aff805a37 Mon Sep 17 00:00:00 2001 From: El Haddoury Younes Date: Tue, 10 Feb 2026 10:55:53 +0100 Subject: [PATCH] erstmal bild hochladet dann mapt biometrische data in .yml und detectiert gesichte , muss immer noch debuggt werden -- second commit --- bildPy/.idea/.gitignore | 10 +++ bildPy/.idea/.name | 1 + bildPy/.idea/bildPy.iml | 10 +++ .../inspectionProfiles/profiles_settings.xml | 6 ++ bildPy/.idea/misc.xml | 7 ++ bildPy/.idea/modules.xml | 8 ++ bildPy/src/source.py | 73 ++++++++++++++++++- 7 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 bildPy/.idea/.gitignore create mode 100644 bildPy/.idea/.name create mode 100644 bildPy/.idea/bildPy.iml create mode 100644 bildPy/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 bildPy/.idea/misc.xml create mode 100644 bildPy/.idea/modules.xml diff --git a/bildPy/.idea/.gitignore b/bildPy/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/bildPy/.idea/.gitignore @@ -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/ diff --git a/bildPy/.idea/.name b/bildPy/.idea/.name new file mode 100644 index 0000000..02a04b2 --- /dev/null +++ b/bildPy/.idea/.name @@ -0,0 +1 @@ +source.py \ No newline at end of file diff --git a/bildPy/.idea/bildPy.iml b/bildPy/.idea/bildPy.iml new file mode 100644 index 0000000..6229028 --- /dev/null +++ b/bildPy/.idea/bildPy.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/bildPy/.idea/inspectionProfiles/profiles_settings.xml b/bildPy/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/bildPy/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/bildPy/.idea/misc.xml b/bildPy/.idea/misc.xml new file mode 100644 index 0000000..590a59e --- /dev/null +++ b/bildPy/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/bildPy/.idea/modules.xml b/bildPy/.idea/modules.xml new file mode 100644 index 0000000..12ac33a --- /dev/null +++ b/bildPy/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/bildPy/src/source.py b/bildPy/src/source.py index 5265d8a..9d694d9 100644 --- a/bildPy/src/source.py +++ b/bildPy/src/source.py @@ -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 \ No newline at end of file