[Vision AI] Blackbox Lane Intrusion & Super-Resolution ANPR: 6-Stage End-to-End Pipeline & Real-Time Constraints (#1)

๐ Key Takeaways (TL;DR)
- Problem: Low-resolution dashcam footage suffers from severe vehicle vibration, nighttime backlighting, and heavy motion blur, making direct license plate recognition and lane violation tracking extremely error-prone.
- Solution: Designed a unified 6-stage vision architecture: Canny/Hough lane extraction -> YOLOv3 vehicle detection -> polygon IoU lane violation calculation -> YOLOv5 plate localization -> EDSR_x4 super-resolution -> EasyOCR temporal voting.
- Result: Constructed an end-to-end Python pipeline achieving robust vehicle tracking and lane boundary monitoring even under degraded dashcam conditions.
1. Project Background: Why Dashcam Vision is Hardโ
In intelligent transportation systems (ITS) and autonomous traffic enforcement, real-time lane intrusion detection and automatic number plate recognition (ANPR) are foundational capabilities. However, real-world dashcam footage presents severe optical challenges:
- Extreme Low Resolution & Blurred Textures: The license plate of a leading or overtaking vehicle often spans merely 30x15 to 50x25 pixels across a 640x480 frame, causing alphanumeric strokes to merge into indistinct blobs.
- Vehicle Vibration & Rolling Shutter Distortions: Road bumps, sudden decelerations, and perspective shifts distort straight lane boundaries.
- Real-Time Latency Bottlenecks: Executing heavy full-frame vision transformers per frame results in fatal FPS drops, disabling real-time tracking.
2. 6-Stage Hierarchical Pipeline Architectureโ
To achieve both high precision and high throughput, we modularized the system into a 6-stage decoupled pipeline:
flowchart TD
Raw["Raw Dashcam Frame 640x480"] --> L1["Stage 1: Canny + Hough Dynamic Lane Extraction"]
Raw --> L2["Stage 2: YOLOv3-tiny Vehicle Detection"]
L1 & L2 --> L3["Stage 3: Vehicle Footprint & Lane Polygon IoU Intrusion Metric"]
L3 -- If Intrusion Triggered --> L4["Stage 4: Localized YOLOv5 Plate Detection in Vehicle ROI"]
L4 --> L5["Stage 5: EDSR_x4 Deep 4x Super-Resolution"]
L5 --> L6["Stage 6: EasyOCR + Regex + Temporal Majority Voting"]
L6 --> Result["Confirmed Violation Plate: 64๊ฐ1511"]

Decoupled Processing Responsibilitiesโ
- Lane Extraction: Trapezoidal dynamic ROI masking, Canny edge detection, and slope filtering isolate driving corridor bounds.
- Vehicle Detection: Lightweight YOLOv3-tiny outputs candidate vehicle bounding boxes in milliseconds.
- Intrusion Criterion: Computes geometric Intersection-over-Union (IoU > 0.05) between vehicle tire footprint and the lane boundary polygon.
- Plate Localization: YOLOv5 (
lp_det.pt) evaluates only the cropped vehicle ROI, saving immense compute cycles. - Super-Resolution: The cropped plate patch is passed through a deep EDSR_x4 neural network, reconstructing high-frequency character contours.
- OCR & Majority Voting: EasyOCR extracts alphanumeric tokens, which undergo Korean syntax regex validation and temporal multi-frame voting to confirm the plate number.
3. Core System Parameters (CONFIG)โ
CONFIG = {
"output_width": 640,
"output_height": 480,
"conf_threshold_vehicle": 0.5,
"nms_threshold_vehicle": 0.4,
"min_vehicle_w": 70,
"min_vehicle_h": 70,
"lane_iou_threshold": 0.05,
"detection_interval": 15,
"min_plate_area_for_ocr": 1200,
"plate_history_size": 7,
"plate_confirm_threshold": 3,
"sr_model": "EDSR_x4.pb",
"yolo_plate_model": "lp_det.pt"
}
4. Real Runtime Errors & Pipeline Integration Pitfallsโ
During end-to-end integration of all six stages on 1080p60 H.264 dashcam streams, two pipeline-level bottlenecks surfaced before individual module tuning:
Bug 1: Synchronous cv2.VideoCapture.read() Buffer Starvation & Frame Dropsโ
When Stage 5 (EDSR_x4) and Stage 6 (EasyOCR) ran synchronously on the main capture thread whenever a lane violation occurred, the 60~120ms spike stalled cap.read(), causing FFmpeg H.264 decoding artifacts on subsequent P-frames and dropping tracking continuity for adjacent vehicles.
- Fix: Decoupled the pipeline into two threads connected by a bounded
queue.Queue(maxsize=4):- Real-Time Tracking Thread (30+ FPS): Runs Stages 1โ3 (
Canny/Hough+YOLOv3-tiny/CSRT+Polygon IoU). When a violation is triggered, it pushes the cropped vehicle ROI packet(track_id, frame_idx, vehicle_roi)into the asynchronous queue without blocking frame ingestion. - Heavy OCR Worker Thread: Consumes ROI packets asynchronously to run Stage 4 (
YOLOv5 lp_det.pt), Stage 5 (EDSR_x4), and Stage 6 (EasyOCRvoting).
- Real-Time Tracking Thread (30+ FPS): Runs Stages 1โ3 (
Bug 2: OpenCV BGR vs PyTorch RGB Channel Inversion in Cropped YOLOv5 Inputsโ
Passing vehicle_roi (sliced directly from an OpenCV BGR frame) into the PyTorch YOLOv5 hub model without cv2.cvtColor(vehicle_roi, cv2.COLOR_BGR2RGB) reduced daytime yellow commercial license plate recall from 94.2% to 61.5% because yellow (R+G) was misinterpreted as cyan (G+B).
- Fix: Standardized an explicit
BGR -> RGBconversion and contiguous memory layout (np.ascontiguousarray) at the Stage 3-to-4 boundary.
5. Next in This Seriesโ
In Post #2: Dynamic Lane Boundary Extraction & Geometric IoU Intrusion Criterion, we examine Canny edge filtering, probabilistic Hough transform mathematics (HoughLinesP), slope-based outlier rejection, and the geometric polygon IoU intrusion criterion.
