Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -42,7 +42,7 @@ def detect_and_read_plate(image):
|
|
| 42 |
logger.info("Starting image processing for license plate detection")
|
| 43 |
try:
|
| 44 |
detected_texts = []
|
| 45 |
-
results = model(image, conf=0.
|
| 46 |
logger.info(f"YOLO model returned {len(results)} results")
|
| 47 |
|
| 48 |
for result in results:
|
|
@@ -52,13 +52,9 @@ def detect_and_read_plate(image):
|
|
| 52 |
|
| 53 |
for box, conf in zip(boxes, confidences):
|
| 54 |
x1, y1, x2, y2 = map(int, box)
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
# Filter by aspect ratio (license plates typically have width/height ~2-5)
|
| 59 |
-
aspect_ratio = width / height if height > 0 else 0
|
| 60 |
-
if not (2.0 <= aspect_ratio <= 5.0) or width < 50 or height < 10:
|
| 61 |
-
logger.warning(f"Skipping box with aspect ratio {aspect_ratio:.2f}, size {width}x{height}")
|
| 62 |
continue
|
| 63 |
|
| 64 |
# Crop the detected license plate
|
|
@@ -74,8 +70,8 @@ def detect_and_read_plate(image):
|
|
| 74 |
for res in ocr_result:
|
| 75 |
text = res[1]
|
| 76 |
confidence = res[2]
|
| 77 |
-
#
|
| 78 |
-
if re.match(r'^[A-Z0-9\s\-]
|
| 79 |
detected_texts.append(f"{text} (conf: {conf:.2f})")
|
| 80 |
logger.info(f"Detected Plate: {text} (YOLO conf: {conf:.2f}, OCR conf: {confidence:.2f})")
|
| 81 |
else:
|
|
|
|
| 42 |
logger.info("Starting image processing for license plate detection")
|
| 43 |
try:
|
| 44 |
detected_texts = []
|
| 45 |
+
results = model(image, conf=0.1) # Lower confidence to increase detections
|
| 46 |
logger.info(f"YOLO model returned {len(results)} results")
|
| 47 |
|
| 48 |
for result in results:
|
|
|
|
| 52 |
|
| 53 |
for box, conf in zip(boxes, confidences):
|
| 54 |
x1, y1, x2, y2 = map(int, box)
|
| 55 |
+
# Minimal size filter to skip tiny boxes
|
| 56 |
+
if (x2 - x1) < 20 or (y2 - y1) < 10:
|
| 57 |
+
logger.warning(f"Skipping small box: ({x1}, {y1}, {x2}, {y2})")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
continue
|
| 59 |
|
| 60 |
# Crop the detected license plate
|
|
|
|
| 70 |
for res in ocr_result:
|
| 71 |
text = res[1]
|
| 72 |
confidence = res[2]
|
| 73 |
+
# Light filtering: prefer alphanumeric, avoid long text
|
| 74 |
+
if len(text) <= 12 and confidence > 0.2 and re.match(r'^[A-Z0-9\s\-]+$', text):
|
| 75 |
detected_texts.append(f"{text} (conf: {conf:.2f})")
|
| 76 |
logger.info(f"Detected Plate: {text} (YOLO conf: {conf:.2f}, OCR conf: {confidence:.2f})")
|
| 77 |
else:
|