Spaces:
Build error
Build error
Commit
·
08cbfa1
1
Parent(s):
9abbee1
Corregir error en resize: Añadir verificaciones de validez de imágenes
Browse files- streamlit_app.py +43 -1
streamlit_app.py
CHANGED
|
@@ -590,9 +590,49 @@ def main():
|
|
| 590 |
st.session_state.feature_camera_running = True
|
| 591 |
|
| 592 |
def stop_feature_camera():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 593 |
st.session_state.feature_camera_running = False
|
| 594 |
st.session_state.feature_camera_stopped = True
|
| 595 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 596 |
if app_mode == "About":
|
| 597 |
st.markdown("""
|
| 598 |
## About This App
|
|
@@ -2226,7 +2266,9 @@ def main():
|
|
| 2226 |
# Reducir tamaño del frame para procesamiento más rápido
|
| 2227 |
scale_factor = 0.5
|
| 2228 |
h, w = img.shape[:2]
|
| 2229 |
-
small_img =
|
|
|
|
|
|
|
| 2230 |
|
| 2231 |
# Detect faces - la función ahora devuelve directamente los bboxes
|
| 2232 |
bboxes = detect_face_dnn(face_net, small_img, confidence_threshold)
|
|
|
|
| 590 |
st.session_state.feature_camera_running = True
|
| 591 |
|
| 592 |
def stop_feature_camera():
|
| 593 |
+
# Función auxiliar para verificar si una imagen es válida antes de redimensionar
|
| 594 |
+
def is_valid_image(img):
|
| 595 |
+
if img is None:
|
| 596 |
+
return False
|
| 597 |
+
try:
|
| 598 |
+
# Verificar que la imagen tenga dimensiones válidas y datos
|
| 599 |
+
return img.size > 0 and len(img.shape) >= 2 and img.shape[0] > 0 and img.shape[1] > 0
|
| 600 |
+
except:
|
| 601 |
+
return False
|
| 602 |
+
|
| 603 |
+
# Función auxiliar para redimensionar de forma segura
|
| 604 |
+
def safe_resize(img, target_size):
|
| 605 |
+
if is_valid_image(img):
|
| 606 |
+
try:
|
| 607 |
+
return cv2.resize(img, target_size)
|
| 608 |
+
except Exception as e:
|
| 609 |
+
print(f"Error al redimensionar: {str(e)}")
|
| 610 |
+
return None
|
| 611 |
+
return None
|
| 612 |
+
|
| 613 |
st.session_state.feature_camera_running = False
|
| 614 |
st.session_state.feature_camera_stopped = True
|
| 615 |
|
| 616 |
+
# Función auxiliar para verificar si una imagen es válida antes de redimensionar
|
| 617 |
+
def is_valid_image(img):
|
| 618 |
+
if img is None:
|
| 619 |
+
return False
|
| 620 |
+
try:
|
| 621 |
+
# Verificar que la imagen tenga dimensiones válidas y datos
|
| 622 |
+
return img.size > 0 and len(img.shape) >= 2 and img.shape[0] > 0 and img.shape[1] > 0
|
| 623 |
+
except:
|
| 624 |
+
return False
|
| 625 |
+
|
| 626 |
+
# Función auxiliar para redimensionar de forma segura
|
| 627 |
+
def safe_resize(img, target_size):
|
| 628 |
+
if is_valid_image(img):
|
| 629 |
+
try:
|
| 630 |
+
return cv2.resize(img, target_size)
|
| 631 |
+
except Exception as e:
|
| 632 |
+
st.error(f"Error al redimensionar: {str(e)}")
|
| 633 |
+
return None
|
| 634 |
+
return None
|
| 635 |
+
|
| 636 |
if app_mode == "About":
|
| 637 |
st.markdown("""
|
| 638 |
## About This App
|
|
|
|
| 2266 |
# Reducir tamaño del frame para procesamiento más rápido
|
| 2267 |
scale_factor = 0.5
|
| 2268 |
h, w = img.shape[:2]
|
| 2269 |
+
small_img = safe_resize(img, (int(w * scale_factor), int(h * scale_factor)))
|
| 2270 |
+
if small_img is None:
|
| 2271 |
+
return frame
|
| 2272 |
|
| 2273 |
# Detect faces - la función ahora devuelve directamente los bboxes
|
| 2274 |
bboxes = detect_face_dnn(face_net, small_img, confidence_threshold)
|