From 9b15c7a4805fe3d284bb91b6405c729262645931 Mon Sep 17 00:00:00 2001 From: raven Date: Tue, 13 Jan 2026 13:15:16 -0300 Subject: [PATCH] Fix guardado de imagenes --- alpr-service/main.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/alpr-service/main.py b/alpr-service/main.py index 144d6da..a7f018a 100644 --- a/alpr-service/main.py +++ b/alpr-service/main.py @@ -5,6 +5,7 @@ import os import time import threading import re +import numpy as np from datetime import datetime from queue import Queue from flask import Flask, Response, jsonify @@ -43,6 +44,11 @@ def save_plate_capture(plate_number, full_frame): """Guarda la captura de la patente para el dataset con cooldown""" current_time = time.time() + # Validar que el frame no esté vacío + if full_frame is None or full_frame.size == 0: + print(f"⚠️ Empty frame, skipping save for {plate_number}") + return False + # Verificar cooldown with captures_lock: if plate_number in recent_captures: @@ -56,10 +62,23 @@ def save_plate_capture(plate_number, full_frame): try: timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") + # Hacer una copia profunda del frame para evitar race conditions + frame_to_save = np.copy(full_frame) + # Solo guardar frame completo filename = f"{plate_number}_{timestamp}.jpg" filepath = f"{DATASET_DIR}/{filename}" - cv2.imwrite(filepath, full_frame, [cv2.IMWRITE_JPEG_QUALITY, 95]) + + # Guardar imagen + success = cv2.imwrite(filepath, frame_to_save, [cv2.IMWRITE_JPEG_QUALITY, 95]) + + # Verificar que el archivo se guardó correctamente + if not success or not os.path.exists(filepath) or os.path.getsize(filepath) == 0: + print(f"❌ Failed to save image for {plate_number}") + # Eliminar archivo vacío si existe + if os.path.exists(filepath): + os.remove(filepath) + return False # Contar total de capturas total_count = len([f for f in os.listdir(DATASET_DIR) if f.endswith('.jpg')])