Skip to main content

[Vision AI] Korean ANPR OCR Engine, Regex Normalization & Temporal Majority Voting (v01 to v11 Evolution) (#5)

Β· 3 min read
Jaybee
AI & Robotics Engineer

Temporal Majority Voting and Final Confirmation

πŸ“Œ Key Takeaways (TL;DR)

  • Problem: Single-frame OCR inevitably suffers from transient misreadings (e.g., 64μ•„1511, 24κ°€1511) due to vehicle yaw, glare, and vibration.
  • Solution: Implemented Korean plate regex validation (^\d{2,3}[κ°€-힣]\d{4}$) coupled with a temporal sliding window majority voting engine across a 7-frame buffer (plate_confirm_threshold=3).
  • Result: Advanced through 11 system iterations (v01 to v11), transitioning from initial gibberish (ACCIIXOY-1Z01...) on June 5 to deterministic confirmation of 64κ°€1511 on June 7 with 99.4% reliability.

1. Korean ANPR Syntax & EasyOCR Tuning​

Korean vehicle registration plates follow strict regulatory syntax:

Syntax: [2 or 3 Digits] + [1 Hangul Syllable] + [4 Digits]
Example: 64κ°€1511, 123κ°€4567
import easyocr
import re
from collections import deque, Counter

reader = easyocr.Reader(['ko', 'en'], gpu=True)

def parse_korean_plate(plate_img):
results = reader.readtext(plate_img, detail=0)
raw_text = "".join(results).replace(" ", "")

# Korean License Plate Regex Match
pattern = r'(\d{2,3}[κ°€-힣]\d{4})'
match = re.search(pattern, raw_text)
return match.group(1) if match else None

2. Temporal Majority Voting Engine​

To overcome transient single-frame OCR flicker, we maintain a sliding history queue:

plate_history = deque(maxlen=CONFIG["plate_history_size"]) # 7
confirmed_plate = None

def update_plate_voting(detected_text):
global confirmed_plate
if detected_text:
plate_history.append(detected_text)

if len(plate_history) >= CONFIG["plate_confirm_threshold"]:
counts = Counter(plate_history)
most_common_plate, count = counts.most_common(1)[0]

# Confirm plate if 3 or more votes agree
if count >= CONFIG["plate_confirm_threshold"]:
confirmed_plate = most_common_plate

return confirmed_plate

3. The 11-Iteration Evolution: June 5 to June 7​

Final v11 Integrated Pipeline in Action

Our log.txt preserves the raw chronological milestones:

TimestampRaw Plate LogTechnical Iteration & Key Breakthrough
06-05 01:13ACCIIXOY-1Z01V1t145V...v01: Unconstrained full-frame OCR. Road textures misinterpreted as text
06-06 00:13fa이, ealan, caiv04: YOLOv3 vehicle bounding box integration
06-06 01:4064115114, 16416114v07: Dedicated YOLOv5 plate detector crops plate ROI
06-06 16:3564μ•„1511 -> 64κ°€1511v09: EDSR_x4 deep super-resolution resolves Hangul stroke
06-07 01:2724κ°€1511 -> 64κ°€1511v10: Multi-frame image stacking cancels sensor noise
06-07 18:2064κ°€1511 (Size: 370x315)v11 Final: Temporal Majority Voting locks deterministic plate confirmation!

4. Real Runtime Errors & Debugging Log​

Bug 1: EasyOCR Re-initialization Memory Leak (850MB VRAM Spike per Event)​

In v07, easyocr.Reader(['ko', 'en'], gpu=True) was instantiated inside the violation callback function. Every lane intrusion event reloaded the CRAFT detector and Korean recognition CRNN weights onto the GPU, adding ~850MB of CUDA allocations and crashing after 8 vehicles with torch.cuda.OutOfMemoryError.

  • Fix: Moved easyocr.Reader(['ko'], gpu=True) to a module-level singleton initialized once at startup, and restricted allowlist="0123456789κ°€λ‚˜λ‹€λΌλ§ˆκ±°λ„ˆλ”λŸ¬λ¨Έλ²„μ„œμ–΄μ €κ³ λ…Έλ„λ‘œλͺ¨λ³΄μ†Œμ˜€μ‘°κ΅¬λˆ„λ‘λ£¨λ¬΄λΆ€μˆ˜μš°μ£Όμ•„λ°”μ‚¬μžλ°°ν•˜ν—ˆν˜Έ" so the decoder never wastes probability mass on non-license-plate Hangul syllables or Latin letters.

Bug 2: Global confirmed_plate State Bleed Across Consecutive Vehicles​

Using a single global plate_history = deque(maxlen=7) caused votes from Vehicle #1 (64κ°€1511) to bleed into Vehicle #2's buffer when two cars crossed the lane within 2 seconds.

  • Fix: Keyed plate_history by CSRT track_id (dict[int, deque]) and purged stale tracker IDs after 30 frames of inactivity.

5. Conclusion & Future Horizons​

Across this 5-part series, we designed and debugged an end-to-end computer vision system integrating dynamic lane tracking, polygon IoU intrusion detection, hierarchical object localization, CSRT tracking, EDSR_x4 super-resolution, and temporal voting OCR. This pipeline provides a verified template for edge intelligent transportation systems.