muddasser commited on
Commit
a34cd68
·
verified ·
1 Parent(s): 27ef20f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
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.1) # Lower confidence to increase detections
46
  logger.info(f"YOLO model returned {len(results)} results")
47
 
48
  for result in results:
@@ -52,7 +52,7 @@ def detect_and_read_plate(image):
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
@@ -70,7 +70,7 @@ def detect_and_read_plate(image):
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})")
@@ -90,7 +90,7 @@ def detect_and_read_plate(image):
90
  # Create Gradio interface
91
  with gr.Blocks() as demo:
92
  gr.Markdown("# Automatic Number Plate Recognition (ANPR)")
93
- gr.Markdown("Upload an image of a car to detect and read its license plate.")
94
 
95
  with gr.Row():
96
  image_input = gr.Image(type="numpy", label="Upload an image of a car")
 
42
  logger.info("Starting image processing for license plate detection")
43
  try:
44
  detected_texts = []
45
+ results = model(image, conf=0.1) # Low confidence for broader detection
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
56
  if (x2 - x1) < 20 or (y2 - y1) < 10:
57
  logger.warning(f"Skipping small box: ({x1}, {y1}, {x2}, {y2})")
58
  continue
 
70
  for res in ocr_result:
71
  text = res[1]
72
  confidence = res[2]
73
+ # Light filtering: prefer alphanumeric, avoid overly 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})")
 
90
  # Create Gradio interface
91
  with gr.Blocks() as demo:
92
  gr.Markdown("# Automatic Number Plate Recognition (ANPR)")
93
+ gr.Markdown("Upload an image of a car to detect and read its license plate. Results may take a few seconds.")
94
 
95
  with gr.Row():
96
  image_input = gr.Image(type="numpy", label="Upload an image of a car")