Skip to content

Add a vehicle-crop fallback so plates in wide / high-resolution scenes still read#26

Open
chsbusch-dot wants to merge 2 commits into
codeproject:mainfrom
chsbusch-dot:alpr-vehicle-crop-fallback
Open

Add a vehicle-crop fallback so plates in wide / high-resolution scenes still read#26
chsbusch-dot wants to merge 2 commits into
codeproject:mainfrom
chsbusch-dot:alpr-vehicle-crop-fallback

Conversation

@chsbusch-dot

Copy link
Copy Markdown

Problem

The plate detector runs at YOLO size=640, so the whole frame is resized to 640px wide before detection. On wide-angle or high-resolution (e.g. 4K) cameras a license plate is a small part of the scene and, after that resize, can shrink to ~10px — too small to detect — even though it is perfectly legible in the source image. The module then returns "No plates found" on cameras that clearly show plates.

Example: a ~60px-wide plate in a 3840×2160 frame becomes ~10px after the 640 resize. (Commonly hit when Blue Iris / Frigate / Agent-DVR send full-resolution frames, but this is a general high-resolution-scene issue, not vendor-specific.)

Fix

Two-pass detection in ALPR.py:

  1. Detect plates on the full frame — unchanged fast path.
  2. If that finds nothing, run general object detection for vehicles, crop each car / truck / bus / motorcycle (with padding plus an extra lower/front-of-vehicle crop), and run the plate detector on those crops. Plate boxes are translated back to full-frame coordinates, de-duplicated by IoU, and then OCR'd exactly as before.

Because a crop is a small region of the original image, the plate keeps its pixels through the 640 resize and detects normally. Well-presented full-frame plates still take the original fast path — the fallback only runs on a miss.

Tuning (constants near the top of ALPR.py)

  • vehicle_confidence (0.25) — minimum confidence to treat a detection as a vehicle
  • max_vehicle_crops (8) — cap on vehicles cropped per frame (bounds worst-case latency)
  • vehicle_labels — object classes to crop

Cost

A miss adds one object-detection pass plus up to max_vehicle_crops × 2 plate passes, so a fallback read is slower than a direct hit (~1s vs ~150ms on our hardware). Direct hits are unaffected.

Testing

  • python3 -m py_compile ALPR.py, git diff --check
  • Validated live against real 4K frames that previously returned nothing: they now read — localization succeeds on the crop, OCR path unchanged.

@chsbusch-dot chsbusch-dot marked this pull request as ready for review July 2, 2026 19:15
Each full-frame miss fans out to max_vehicle_crops x 2 plate-detection passes;
3 covers the common case (a car or two in view) while keeping worst-case latency
and GPU load bounded on busy scenes / small GPUs. Raise it if a scene routinely
has more vehicles that need reading.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant