Fix guardado de imagenes
This commit is contained in:
@@ -5,6 +5,7 @@ import os
|
|||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
import re
|
import re
|
||||||
|
import numpy as np
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from flask import Flask, Response, jsonify
|
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"""
|
"""Guarda la captura de la patente para el dataset con cooldown"""
|
||||||
current_time = time.time()
|
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
|
# Verificar cooldown
|
||||||
with captures_lock:
|
with captures_lock:
|
||||||
if plate_number in recent_captures:
|
if plate_number in recent_captures:
|
||||||
@@ -56,10 +62,23 @@ def save_plate_capture(plate_number, full_frame):
|
|||||||
try:
|
try:
|
||||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
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
|
# Solo guardar frame completo
|
||||||
filename = f"{plate_number}_{timestamp}.jpg"
|
filename = f"{plate_number}_{timestamp}.jpg"
|
||||||
filepath = f"{DATASET_DIR}/{filename}"
|
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
|
# Contar total de capturas
|
||||||
total_count = len([f for f in os.listdir(DATASET_DIR) if f.endswith('.jpg')])
|
total_count = len([f for f in os.listdir(DATASET_DIR) if f.endswith('.jpg')])
|
||||||
|
|||||||
Reference in New Issue
Block a user