Add crop refinement, finger removal, and local LLM naming

- vision/refine.py: tighten crops to the paper band (removes mat
  margins and hands beside receipts) and inpaint border-connected
  skin regions so fingers disappear from output
- llm/vision.py: identify documents with a local Ollama vision model
  (qwen2.5vl); extracts vendor/date/total/form code and flags quality
  issues (fingers, blur, glare); falls back to Tesseract when down
- pipeline: drop blank pages, dedupe consecutive captures of the same
  document, record refine/LLM fields in report and export summary
This commit is contained in:
2026-07-08 18:23:50 -04:00
parent 2c28a623fb
commit a43ab20df6
22 changed files with 1497 additions and 111 deletions
+35 -1
View File
@@ -27,11 +27,45 @@ motion:
document:
# Contours smaller than this fraction of the frame area are ignored.
min_area_ratio: 0.04
# Contours larger than this fraction of the frame are rejected as likely
# background/lighting rather than a document.
max_area_ratio: 0.92
# Reject candidates whose long side is more than this many times their
# short side (filters out thin slivers/edge-strip false detections).
max_aspect: 6.0
# Canny edge detection thresholds.
canny_low: 50
canny_high: 150
# Apply contrast enhancement (CLAHE) to crops for OCR-readiness.
# Contour search runs on a frame downscaled to this width (then the
# winning quad is scaled back up for the full-resolution crop). Keeps
# edge/gap-closing behavior consistent regardless of source resolution —
# important for 4K phone video.
detect_width: 1000
# Bake illumination-normalization + contrast enhancement into the saved
# crop/PDF (grayscale "flattened scan" look). OCR always uses this
# enhancement internally regardless of this setting.
enhance: false
# Auto-detect and correct 0/90/180/270 rotation before OCR/PDF export.
auto_rotate: true
# Tighten crops to the actual paper region (cuts mat margins/hands) and
# inpaint fingers pressing on the page.
refine: true
remove_fingers: true
# Split separate document placements when no contour is seen for this long.
event_gap_s: 2.0
# Ignore single-frame detection blips.
event_min_samples: 2
llm:
# Identify/name documents with a local Ollama vision model (all offline).
# Reads whole documents at once — far more robust than Tesseract for
# curled receipts and stylized logos — and flags quality issues
# (fingers_visible, blurry, glare) in export_summary.csv.
# Slower: ~20-40s per document. Falls back to Tesseract when Ollama is down.
enabled: true
model: qwen2.5vl
base_url: http://localhost:11434
timeout_s: 180
speech:
# Window around a capture event in which to look for a spoken description.