Upload api.py
Browse files
api.py
CHANGED
|
@@ -74,6 +74,7 @@ async def create_initial_casting(
|
|
| 74 |
min_cluster_size: int = Form(...),
|
| 75 |
voice_epsilon: float = Form(0.5),
|
| 76 |
voice_min_cluster_size: int = Form(2),
|
|
|
|
| 77 |
):
|
| 78 |
"""
|
| 79 |
Crea un job para procesar el vídeo de forma asíncrona.
|
|
@@ -98,6 +99,7 @@ async def create_initial_casting(
|
|
| 98 |
"min_cluster_size": int(min_cluster_size),
|
| 99 |
"voice_epsilon": float(voice_epsilon),
|
| 100 |
"voice_min_cluster_size": int(voice_min_cluster_size),
|
|
|
|
| 101 |
"created_at": datetime.now().isoformat(),
|
| 102 |
"results": None,
|
| 103 |
"error": None
|
|
@@ -205,8 +207,8 @@ def process_video_job(job_id: str):
|
|
| 205 |
raise RuntimeError("No se pudo abrir el vídeo para extracción de caras")
|
| 206 |
fps = cap.get(cv2.CAP_PROP_FPS) or 25.0
|
| 207 |
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT) or 0)
|
| 208 |
-
max_samples = 100
|
| 209 |
-
# Índices de frames equiespaciados
|
| 210 |
if total_frames > 0:
|
| 211 |
frame_indices = sorted(set(np.linspace(0, max(0, total_frames - 1), num=min(max_samples, max(1, total_frames)), dtype=int).tolist()))
|
| 212 |
else:
|
|
@@ -266,7 +268,8 @@ def process_video_job(job_id: str):
|
|
| 266 |
face_cascade = None
|
| 267 |
boxes_haar = []
|
| 268 |
if face_cascade is not None and not face_cascade.empty():
|
| 269 |
-
|
|
|
|
| 270 |
for (x, y, w, h) in faces_haar:
|
| 271 |
top, left, bottom, right = max(0, y), max(0, x), min(frame.shape[0], y+h), min(frame.shape[1], x+w)
|
| 272 |
boxes_haar.append((top, right, bottom, left))
|
|
@@ -284,7 +287,8 @@ def process_video_job(job_id: str):
|
|
| 284 |
# Validar que es un bbox real, no el frame completo
|
| 285 |
# Si el bbox es prácticamente el frame completo, descartarlo
|
| 286 |
is_full_frame = (x <= 5 and y <= 5 and w >= frame.shape[1] - 10 and h >= frame.shape[0] - 10)
|
| 287 |
-
|
|
|
|
| 288 |
top, left, bottom, right = max(0, y), max(0, x), min(frame.shape[0], y+h), min(frame.shape[1], x+w)
|
| 289 |
boxes_haar.append((top, right, bottom, left))
|
| 290 |
tmp_detect.unlink(missing_ok=True)
|
|
|
|
| 74 |
min_cluster_size: int = Form(...),
|
| 75 |
voice_epsilon: float = Form(0.5),
|
| 76 |
voice_min_cluster_size: int = Form(2),
|
| 77 |
+
max_frames: int = Form(100),
|
| 78 |
):
|
| 79 |
"""
|
| 80 |
Crea un job para procesar el vídeo de forma asíncrona.
|
|
|
|
| 99 |
"min_cluster_size": int(min_cluster_size),
|
| 100 |
"voice_epsilon": float(voice_epsilon),
|
| 101 |
"voice_min_cluster_size": int(voice_min_cluster_size),
|
| 102 |
+
"max_frames": int(max_frames),
|
| 103 |
"created_at": datetime.now().isoformat(),
|
| 104 |
"results": None,
|
| 105 |
"error": None
|
|
|
|
| 207 |
raise RuntimeError("No se pudo abrir el vídeo para extracción de caras")
|
| 208 |
fps = cap.get(cv2.CAP_PROP_FPS) or 25.0
|
| 209 |
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT) or 0)
|
| 210 |
+
max_samples = job.get("max_frames", 100)
|
| 211 |
+
# Índices de frames equiespaciados
|
| 212 |
if total_frames > 0:
|
| 213 |
frame_indices = sorted(set(np.linspace(0, max(0, total_frames - 1), num=min(max_samples, max(1, total_frames)), dtype=int).tolist()))
|
| 214 |
else:
|
|
|
|
| 268 |
face_cascade = None
|
| 269 |
boxes_haar = []
|
| 270 |
if face_cascade is not None and not face_cascade.empty():
|
| 271 |
+
# Parámetros más estrictos para evitar falsos positivos
|
| 272 |
+
faces_haar = face_cascade.detectMultiScale(gray, scaleFactor=1.08, minNeighbors=5, minSize=(50, 50))
|
| 273 |
for (x, y, w, h) in faces_haar:
|
| 274 |
top, left, bottom, right = max(0, y), max(0, x), min(frame.shape[0], y+h), min(frame.shape[1], x+w)
|
| 275 |
boxes_haar.append((top, right, bottom, left))
|
|
|
|
| 287 |
# Validar que es un bbox real, no el frame completo
|
| 288 |
# Si el bbox es prácticamente el frame completo, descartarlo
|
| 289 |
is_full_frame = (x <= 5 and y <= 5 and w >= frame.shape[1] - 10 and h >= frame.shape[0] - 10)
|
| 290 |
+
# Bbox mínimo de 50x50 para filtrar falsos positivos pequeños
|
| 291 |
+
if w > 50 and h > 50 and not is_full_frame:
|
| 292 |
top, left, bottom, right = max(0, y), max(0, x), min(frame.shape[0], y+h), min(frame.shape[1], x+w)
|
| 293 |
boxes_haar.append((top, right, bottom, left))
|
| 294 |
tmp_detect.unlink(missing_ok=True)
|