APIMONSTER commited on
Commit
5fada55
·
verified ·
1 Parent(s): 8f59c1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -36,19 +36,19 @@ def run_image(img, conf=0.25):
36
  res.boxes.conf.cpu().numpy()):
37
  x1,y1,x2,y2 = box.astype(int)
38
  crop = out[y1:y2, x1:x2]
39
- if crop.size == 0:
40
  continue
41
 
42
  plate_img = cv2.resize(crop, (128, 32))
43
 
44
- # burada dahili tespiti kapattık
45
  try:
46
  recs = ocr.ocr(plate_img, det=False, cls=True)
47
  except Exception:
48
  recs = []
49
 
50
- if recs and recs[0]:
51
- raw_text, ocr_score = recs[0][1][0], recs[0][1][1]
52
  else:
53
  raw_text, ocr_score = "", 0.0
54
 
@@ -69,28 +69,27 @@ def run_video(video_file, conf=0.25):
69
  h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
70
  outfp = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
71
  writer = cv2.VideoWriter(outfp, cv2.VideoWriter_fourcc(*"mp4v"), fps, (w,h))
72
- records = []
73
- idx = 0
74
 
75
  while True:
76
  ret, frame = cap.read()
77
  if not ret: break
78
- idx += 1; t = idx/fps
79
 
80
  res = yolo(frame, conf=conf)[0]
81
  for (x1,y1,x2,y2) in res.boxes.xyxy.cpu().numpy().astype(int):
82
  crop = frame[y1:y2, x1:x2]
83
- if crop.size == 0:
84
  continue
85
 
86
- plate_img = cv2.resize(crop, (128,32))
87
  try:
88
  recs = ocr.ocr(plate_img, det=False, cls=True)
89
  except Exception:
90
  recs = []
91
 
92
- if recs and recs[0]:
93
- raw_text, ocr_score = recs[0][1][0], recs[0][1][1]
94
  else:
95
  raw_text, ocr_score = "", 0.0
96
 
@@ -99,11 +98,11 @@ def run_video(video_file, conf=0.25):
99
  records.append({
100
  "time_s": round(t,2),
101
  "plate": plate,
102
- "conf": round(ocr_score,3)
103
  })
104
 
105
  cv2.rectangle(frame, (x1,y1),(x2,y2), (0,255,0), 2)
106
- cv2.putText(frame, plate, (x1,y1-5),
107
  cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0,255,0), 2)
108
 
109
  writer.write(frame)
 
36
  res.boxes.conf.cpu().numpy()):
37
  x1,y1,x2,y2 = box.astype(int)
38
  crop = out[y1:y2, x1:x2]
39
+ if crop.size == 0:
40
  continue
41
 
42
  plate_img = cv2.resize(crop, (128, 32))
43
 
44
+ # dahili tespit kapalı, sadece tanıma+angle-cls
45
  try:
46
  recs = ocr.ocr(plate_img, det=False, cls=True)
47
  except Exception:
48
  recs = []
49
 
50
+ if recs:
51
+ raw_text, ocr_score = recs[0][0], recs[0][1]
52
  else:
53
  raw_text, ocr_score = "", 0.0
54
 
 
69
  h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
70
  outfp = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
71
  writer = cv2.VideoWriter(outfp, cv2.VideoWriter_fourcc(*"mp4v"), fps, (w,h))
72
+ records, idx = [], 0
 
73
 
74
  while True:
75
  ret, frame = cap.read()
76
  if not ret: break
77
+ idx += 1; t = idx / fps
78
 
79
  res = yolo(frame, conf=conf)[0]
80
  for (x1,y1,x2,y2) in res.boxes.xyxy.cpu().numpy().astype(int):
81
  crop = frame[y1:y2, x1:x2]
82
+ if crop.size == 0:
83
  continue
84
 
85
+ plate_img = cv2.resize(crop, (128, 32))
86
  try:
87
  recs = ocr.ocr(plate_img, det=False, cls=True)
88
  except Exception:
89
  recs = []
90
 
91
+ if recs:
92
+ raw_text, ocr_score = recs[0][0], recs[0][1]
93
  else:
94
  raw_text, ocr_score = "", 0.0
95
 
 
98
  records.append({
99
  "time_s": round(t,2),
100
  "plate": plate,
101
+ "conf": round(ocr_score,3)
102
  })
103
 
104
  cv2.rectangle(frame, (x1,y1),(x2,y2), (0,255,0), 2)
105
+ cv2.putText(frame, plate, (x1, y1-5),
106
  cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0,255,0), 2)
107
 
108
  writer.write(frame)