Spaces:
Running
Running
t544h commited on
Commit ·
f9cf21d
1
Parent(s): ad282a8
Fix: Ajout conf=0.25 pour YOLO et prints de debug
Browse files- cin_validator.py +4 -0
- enhanced/detector.py +19 -7
cin_validator.py
CHANGED
|
@@ -64,11 +64,15 @@ class CINValidator:
|
|
| 64 |
def validate(self, image_url: str, side: str = "recto") -> dict:
|
| 65 |
try:
|
| 66 |
img = self.download_image(image_url)
|
|
|
|
|
|
|
|
|
|
| 67 |
except Exception as e:
|
| 68 |
return {"status": "error", "message": f"Failed to download image: {str(e)}"}
|
| 69 |
|
| 70 |
# 1. Run YOLO Detector
|
| 71 |
detections = self.detector.detect(img)
|
|
|
|
| 72 |
|
| 73 |
# If no card detected
|
| 74 |
if not detections:
|
|
|
|
| 64 |
def validate(self, image_url: str, side: str = "recto") -> dict:
|
| 65 |
try:
|
| 66 |
img = self.download_image(image_url)
|
| 67 |
+
print(f"--- DEBUG SAHL EXPRESS ---")
|
| 68 |
+
print(f"Image téléchargée avec succès. Résolution d'origine : {img.shape}")
|
| 69 |
+
print(f"Demande de validation pour le côté : {side}")
|
| 70 |
except Exception as e:
|
| 71 |
return {"status": "error", "message": f"Failed to download image: {str(e)}"}
|
| 72 |
|
| 73 |
# 1. Run YOLO Detector
|
| 74 |
detections = self.detector.detect(img)
|
| 75 |
+
print(f"Nombre de cartes détectées par YOLO : {len(detections)}")
|
| 76 |
|
| 77 |
# If no card detected
|
| 78 |
if not detections:
|
enhanced/detector.py
CHANGED
|
@@ -151,9 +151,9 @@ class IDCardDetector:
|
|
| 151 |
"""Run YOLO detection."""
|
| 152 |
results = self.model(
|
| 153 |
frame,
|
| 154 |
-
conf=
|
| 155 |
iou=self.config.nms_iou_threshold,
|
| 156 |
-
imgsz=
|
| 157 |
verbose=False,
|
| 158 |
)
|
| 159 |
|
|
@@ -167,10 +167,17 @@ class IDCardDetector:
|
|
| 167 |
cls_id = int(box.cls[0])
|
| 168 |
|
| 169 |
det = Detection(bbox=bbox, confidence=conf, class_id=cls_id)
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
# Apply aspect ratio and area filters
|
| 172 |
if self._validate_detection(det, frame.shape):
|
| 173 |
detections.append(det)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
return detections
|
| 176 |
|
|
@@ -213,22 +220,27 @@ class IDCardDetector:
|
|
| 213 |
"""
|
| 214 |
h, w = frame_shape[:2]
|
| 215 |
frame_area = h * w
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
# Area check
|
| 218 |
area_ratio = det.area / frame_area
|
| 219 |
-
if area_ratio <
|
|
|
|
| 220 |
return False
|
| 221 |
|
| 222 |
# Aspect ratio check (more permissive for tilted/perspective cards)
|
| 223 |
ar = det.aspect_ratio
|
| 224 |
inv_ar = 1.0 / max(ar, 1e-6)
|
| 225 |
effective_ar = max(ar, inv_ar) # Handle both landscape and portrait
|
| 226 |
-
|
|
|
|
|
|
|
| 227 |
return False
|
| 228 |
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
return False
|
| 232 |
|
| 233 |
return True
|
| 234 |
|
|
|
|
| 151 |
"""Run YOLO detection."""
|
| 152 |
results = self.model(
|
| 153 |
frame,
|
| 154 |
+
conf=0.30,
|
| 155 |
iou=self.config.nms_iou_threshold,
|
| 156 |
+
imgsz=640,
|
| 157 |
verbose=False,
|
| 158 |
)
|
| 159 |
|
|
|
|
| 167 |
cls_id = int(box.cls[0])
|
| 168 |
|
| 169 |
det = Detection(bbox=bbox, confidence=conf, class_id=cls_id)
|
| 170 |
+
|
| 171 |
+
# Log de debug pour voir ce que YOLO trouve avant le filtre géométrique
|
| 172 |
+
print(f"--- [DEBUG YOLO] Carte trouvée avec confiance: {conf:.2f} | Bbox: {bbox}")
|
| 173 |
|
| 174 |
# Apply aspect ratio and area filters
|
| 175 |
if self._validate_detection(det, frame.shape):
|
| 176 |
detections.append(det)
|
| 177 |
+
else:
|
| 178 |
+
print(f"--- [DEBUG FILTER] Carte REJETÉE par les filtres géométriques (Taille/Ratio)")
|
| 179 |
+
|
| 180 |
+
print(f"--- [DEBUG FINAL] Nombre de cartes retenues après filtres : {len(detections)}")
|
| 181 |
|
| 182 |
return detections
|
| 183 |
|
|
|
|
| 220 |
"""
|
| 221 |
h, w = frame_shape[:2]
|
| 222 |
frame_area = h * w
|
| 223 |
+
if det.width < 40 or det.height < 40:
|
| 224 |
+
print(f" -> Échec: Carte trop petite ({det.width:.1f}x{det.height:.1f})")
|
| 225 |
+
return False
|
| 226 |
|
| 227 |
# Area check
|
| 228 |
area_ratio = det.area / frame_area
|
| 229 |
+
if area_ratio < 0.05:
|
| 230 |
+
print(f" -> Échec: La carte occupe trop peu de place sur la photo ({area_ratio*100:.1f}%)")
|
| 231 |
return False
|
| 232 |
|
| 233 |
# Aspect ratio check (more permissive for tilted/perspective cards)
|
| 234 |
ar = det.aspect_ratio
|
| 235 |
inv_ar = 1.0 / max(ar, 1e-6)
|
| 236 |
effective_ar = max(ar, inv_ar) # Handle both landscape and portrait
|
| 237 |
+
print(f" -> Stats géométriques : Aspect Ratio effectif = {effective_ar:.2f} | Ratio Aire = {area_ratio*100:.1f}%")
|
| 238 |
+
if effective_ar < 1.0 or effective_ar > 2.3:
|
| 239 |
+
print(f" -> Échec: Aspect Ratio hors limites ({effective_ar:.2f})")
|
| 240 |
return False
|
| 241 |
|
| 242 |
+
|
| 243 |
+
|
|
|
|
| 244 |
|
| 245 |
return True
|
| 246 |
|