„code/facedetection2.py“ löschen
This commit is contained in:
parent
38475f3457
commit
a0d57e4cd8
@ -1,61 +0,0 @@
|
|||||||
"""
|
|
||||||
Abhängigkeiten:
|
|
||||||
- cv2 (OpenCV-Paket)
|
|
||||||
- numpy
|
|
||||||
|
|
||||||
Autor: Ihr Name
|
|
||||||
Datum: Erstellungs- oder Änderungsdatum
|
|
||||||
Version: Modulversion
|
|
||||||
"""
|
|
||||||
|
|
||||||
import cv2
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_alt2.xml")
|
|
||||||
|
|
||||||
def read_video(path):
|
|
||||||
"""
|
|
||||||
Liest ein Video, erkennt Gesichter und extrahiert Regionen von Interesse (ROIs).
|
|
||||||
|
|
||||||
Diese Funktion nimmt einen Pfad zu einer Videodatei und liest das Video. Während des Lesens erkennt sie
|
|
||||||
Gesichter im Video und extrahiert die ROIs (Gesichtsbereiche), die anschließend in einer Liste von Frames
|
|
||||||
gespeichert werden. Die Frames werden für spätere Verarbeitungsschritte skaliert.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
path (str): Der Pfad zur Videodatei.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
tuple: Ein Tupel, bestehend aus:
|
|
||||||
- video_frames (list): Eine Liste von Frames, die die ROIs (Gesichtsbereiche) darstellen.
|
|
||||||
- frame_ct (int): Die Anzahl der extrahierten Frames.
|
|
||||||
- fps (int): Die Bildrate (Frames pro Sekunde) des Videos.
|
|
||||||
"""
|
|
||||||
cap = cv2.VideoCapture(path)
|
|
||||||
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
|
||||||
video_frames = []
|
|
||||||
|
|
||||||
while cap.isOpened():
|
|
||||||
ret, img = cap.read()
|
|
||||||
if not ret:
|
|
||||||
break
|
|
||||||
|
|
||||||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
|
||||||
|
|
||||||
# Detect faces
|
|
||||||
faces = faceCascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
|
|
||||||
|
|
||||||
# Extract ROIs and resize
|
|
||||||
for (x, y, w, h) in faces:
|
|
||||||
face_roi = cv2.resize(img[y:y+h, x:x+w], (500, 500))
|
|
||||||
frame = face_roi.astype("float") / 255.0
|
|
||||||
video_frames.append(frame)
|
|
||||||
|
|
||||||
cap.release()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for frame in video_frames:
|
|
||||||
cv2.imshow("frame", frame)
|
|
||||||
cv2.waitKey(20)
|
|
||||||
cv2.destroyAllWindows()
|
|
||||||
return video_frames, len(video_frames), fps
|
|
Loading…
x
Reference in New Issue
Block a user