erstmal bild hochladet dann mapt biometrische data in .yml und detectiert gesichte , muss immer noch debuggt werden -- second commit
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user