fix dataset: only full frame, 60s cooldown per plate
This commit is contained in:
@@ -30,22 +30,35 @@ detection_lock = threading.Lock()
|
||||
# Cola para procesamiento OCR asíncrono (ahora incluye frame completo)
|
||||
ocr_queue = Queue(maxsize=5)
|
||||
|
||||
# Cooldown para evitar múltiples capturas de la misma patente
|
||||
DATASET_COOLDOWN = 60 # segundos entre capturas de la misma patente
|
||||
recent_captures = {} # {plate_number: timestamp}
|
||||
captures_lock = threading.Lock()
|
||||
|
||||
# Crear carpeta de dataset si no existe
|
||||
os.makedirs(DATASET_DIR, exist_ok=True)
|
||||
print(f"📁 Dataset directory: {DATASET_DIR}")
|
||||
|
||||
def save_plate_capture(plate_number, plate_img, full_frame):
|
||||
"""Guarda la captura de la patente para el dataset"""
|
||||
def save_plate_capture(plate_number, full_frame):
|
||||
"""Guarda la captura de la patente para el dataset con cooldown"""
|
||||
current_time = time.time()
|
||||
|
||||
# Verificar cooldown
|
||||
with captures_lock:
|
||||
if plate_number in recent_captures:
|
||||
elapsed = current_time - recent_captures[plate_number]
|
||||
if elapsed < DATASET_COOLDOWN:
|
||||
return False # Aún en cooldown, no guardar
|
||||
|
||||
# Actualizar timestamp
|
||||
recent_captures[plate_number] = current_time
|
||||
|
||||
try:
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
|
||||
# Guardar imagen recortada de la patente
|
||||
plate_filename = f"{DATASET_DIR}/{plate_number}_{timestamp}_plate.jpg"
|
||||
cv2.imwrite(plate_filename, plate_img, [cv2.IMWRITE_JPEG_QUALITY, 95])
|
||||
|
||||
# Guardar frame completo con contexto
|
||||
frame_filename = f"{DATASET_DIR}/{plate_number}_{timestamp}_full.jpg"
|
||||
cv2.imwrite(frame_filename, full_frame, [cv2.IMWRITE_JPEG_QUALITY, 90])
|
||||
# Solo guardar frame completo
|
||||
filename = f"{DATASET_DIR}/{plate_number}_{timestamp}.jpg"
|
||||
cv2.imwrite(filename, full_frame, [cv2.IMWRITE_JPEG_QUALITY, 95])
|
||||
|
||||
print(f"📸 Saved to dataset: {plate_number}")
|
||||
return True
|
||||
@@ -87,8 +100,8 @@ def ocr_worker(reader):
|
||||
if len(clean_text) >= 6 and validate_plate(clean_text):
|
||||
# Enviar al backend
|
||||
send_plate(clean_text)
|
||||
# Guardar captura para dataset
|
||||
save_plate_capture(clean_text, plate_img, full_frame)
|
||||
# Guardar captura para dataset (con cooldown)
|
||||
save_plate_capture(clean_text, full_frame)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user