An automated device-label recognition tool: crop fields -> barcode decode -> OCR -> structured export (JSONL), with Windows one-click run.
This project is a local batch-processing tool for device label / barcode images. It combines object detection (Roboflow inference), barcode decoding, and OCR to extract Model and SN. The core idea is "locate first, then recognize":
- Detect label areas in the full image using a Roboflow model.
- Crop label areas and then crop model/sn sub-fields.
- Run barcode decoding and OCR on the cropped fields.
- Output structured results (JSONL) and debug logs for tracing and tuning.
Input -> crop -> barcode -> ocr -> postprocess -> output
- End-to-end batch processing: from raw images to results in one run.
- Multi-stage cropping and filtering to improve accuracy.
- Dual-channel decoding: barcode first, OCR as fallback.
- Debug artifacts saved for easier troubleshooting.
- Local/offline dependencies bundled to reduce external setup.
crop.py: stage 1/2 cropping (Roboflow detect + crop)scan2.py: barcode/OCR + structured outputbarcode.py: barcode enhancement pipelinerun_all.py: one-click pipeline entrystart.bat: Windows one-click script
- Windows
- Python 3.10+ (recommended)
- Valid Roboflow API key
- Create
.envin the project root (do not commit):
API_KEY=your_api_key_here
- Double-click
start.bat.
python run_all.py --input ./images --out ./out --format jsonl --log-level info --device cpu
Full options:
python run_all.py --help
- Read images from
new_images/. - Stage 1: detect and crop label areas ->
stage1_labels/. - Stage 2: crop model/sn fields ->
stage2_fields/. scan2.pyruns barcode + OCR.- Outputs
model_sn_ocr.jsonlanddebug_ocr_barcode.log.
stage1_labels/: label cropsstage2_fields/model/: model cropsstage2_fields/sn/: SN cropsmodel_sn_ocr.jsonl: final results (one JSON per line)debug_ocr_barcode.log: debug log Default output is repo root; use--outto change it.
CLI prints:
- total images, total time, average time per image
- SN extraction success rate
- regex pass rate
- error distribution (barcode_fail / ocr_fail / regex_fail)
Single JSONL line:
{"label_id":"img_001__label_1","model":"S380-S8P2T","sn":"4E25XXXXXXXX","model_src":"barcode","sn_src":"ocr","model_raw":"...","sn_raw":"..."}
- Multi-scale upscaling for small barcodes
- ROI cropping to reduce noise
- Rotation attempts (0/90/180/270)
- Regex validation for SN/Model
- Failure samples saved for review
- CSV export and configurable field mapping
- Finer error taxonomy and visual reports
- Incremental CLI processing with resume support
- Lighter releases (optional LFS or model download scripts)
- No results: check image clarity, angle, lighting; or tune crop/thresholds.
- API_KEY missing: ensure
.envexists and is correct. - Unstable results: tune parameters in
crop.py/scan2.py.
.envis excluded from the repo, so API keys are not exposed.- Share
.envprivately when needed. - Do not hard-code API keys.
- Key rotation: update
API_KEYin.envwithout code changes.