Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,7 +52,7 @@ def normalize_ocr(recs):
|
|
| 52 |
def format_plate(s: str) -> str:
|
| 53 |
"""‘DD AAA DDDD’ veya Unknown"""
|
| 54 |
s = re.sub(r'[^A-Z0-9]', '', s.upper())
|
| 55 |
-
m = re.match(r'^(\d{2})([A-Z]{1,3})(
|
| 56 |
return f"{m.group(1)} {m.group(2)} {m.group(3)}" if m else "Unknown"
|
| 57 |
|
| 58 |
# ─── 5) Single-image inference
|
|
@@ -62,9 +62,17 @@ def run_image(img, conf=0.25):
|
|
| 62 |
res = yolo(bgr, conf=conf)[0]
|
| 63 |
out = bgr.copy()
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
crop = out[y1:y2, x1:x2]
|
|
|
|
|
|
|
| 68 |
if crop.size == 0:
|
| 69 |
continue
|
| 70 |
|
|
@@ -103,9 +111,16 @@ def run_video(video_file, conf=0.25):
|
|
| 103 |
idx += 1; t = idx/fps
|
| 104 |
|
| 105 |
res = yolo(frame, conf=conf)[0]
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
if crop.size == 0: continue
|
| 110 |
|
| 111 |
plate_img = cv2.resize(crop, (128,32))
|
|
|
|
| 52 |
def format_plate(s: str) -> str:
|
| 53 |
"""‘DD AAA DDDD’ veya Unknown"""
|
| 54 |
s = re.sub(r'[^A-Z0-9]', '', s.upper())
|
| 55 |
+
m = re.match(r'^(\d{2})([A-Z]{1,3})([A-Z0-9]{2,4})$', s)
|
| 56 |
return f"{m.group(1)} {m.group(2)} {m.group(3)}" if m else "Unknown"
|
| 57 |
|
| 58 |
# ─── 5) Single-image inference
|
|
|
|
| 62 |
res = yolo(bgr, conf=conf)[0]
|
| 63 |
out = bgr.copy()
|
| 64 |
|
| 65 |
+
# YOLO’dan gelen tüm kutuları al
|
| 66 |
+
boxes = res.boxes.xyxy.cpu().numpy().astype(int)
|
| 67 |
+
if len(boxes):
|
| 68 |
+
# genişlik*yükseklik’e göre en büyüğü seç
|
| 69 |
+
w = boxes[:,2] - boxes[:,0]
|
| 70 |
+
h = boxes[:,3] - boxes[:,1]
|
| 71 |
+
idx = int(np.argmax(w * h))
|
| 72 |
+
x1,y1,x2,y2 = boxes[idx]
|
| 73 |
crop = out[y1:y2, x1:x2]
|
| 74 |
+
|
| 75 |
+
|
| 76 |
if crop.size == 0:
|
| 77 |
continue
|
| 78 |
|
|
|
|
| 111 |
idx += 1; t = idx/fps
|
| 112 |
|
| 113 |
res = yolo(frame, conf=conf)[0]
|
| 114 |
+
# YOLO’dan gelen tüm kutuları al
|
| 115 |
+
boxes = res.boxes.xyxy.cpu().numpy().astype(int)
|
| 116 |
+
if len(boxes):
|
| 117 |
+
# genişlik*yükseklik’e göre en büyüğü seç
|
| 118 |
+
w = boxes[:,2] - boxes[:,0]
|
| 119 |
+
h = boxes[:,3] - boxes[:,1]
|
| 120 |
+
idx = int(np.argmax(w * h))
|
| 121 |
+
x1,y1,x2,y2 = boxes[idx]
|
| 122 |
+
crop = out[y1:y2, x1:x2]
|
| 123 |
+
|
| 124 |
if crop.size == 0: continue
|
| 125 |
|
| 126 |
plate_img = cv2.resize(crop, (128,32))
|