Skip to content

feat: add batch processing for image directories - #4

Merged
estherg12 merged 2 commits into
estherg12:mainfrom
Chirudeva-Reddy:feat/batch-directory-processing
Sep 14, 2026
Merged

estherg12 merged 2 commits into
estherg12:mainfrom
Chirudeva-Reddy:feat/batch-directory-processing

Conversation

@Chirudeva-Reddy

@Chirudeva-Reddy Chirudeva-Reddy commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #2.

This PR adds directory-level batch processing for handwriting OCR transcription:

  • Batch Processing Module (batch_process.py):
    • get_image_files(directory): Discovers and sorts all supported image formats (.jpg, .jpeg, .png, case-insensitive).
    • process_image(image_path, ...): Chains line detection with measure_text_lines(), crops and saves text lines with crop_and_save_lines(), transcribes lines, cleans up temporary crop files, and exports transcriptions to .txt and .pdf files named directly after the source image stem (output/<image_stem>.txt and output/<image_stem>.pdf) as well as raw/NLP variants.
    • batch_process(directory, ...): Processes an entire folder of handwriting images.
    • Safe intermediate crop cleanup via cleanup_line_crops() preserving final output artifacts.
    • export_to_pdf(): Robust Unicode punctuation sanitization (em-dashes, en-dashes, typographical quotes, bullets, ellipses) preventing FPDFUnicodeEncodingException under Latin-1 fonts.
  • CLI & Pipeline Integration (main.py):
    • Adds argparse to main.py supporting positional directory/image path, --folder DIR / -f, --image FILE / -i, --output DIR / -o, and --model-dir PATH / -m.
  • Unit Tests (tests/test_batch_process.py):
    • 9 automated tests covering file discovery, non-existent directories, export formatting, Unicode punctuation handling, custom transcription mock pipelines, end-to-end single image processing with exact naming checks, and multi-image directory batching.
  • Code Quality:
    • Passes Flake8 checks without unused imports or line-length violations.
  • Documentation:
    • Updated README.md setup & usage instructions with single image and batch directory processing commands.

Verification

  • uv run pytest: All 13 tests pass cleanly (test_batch_process.py and test_count_lines.py).
  • uv run flake8: 0 errors/warnings on new code.

@estherg12 estherg12 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your interest and collaboration!!

Everthing seems fine.

@estherg12
estherg12 merged commit b4d63f0 into estherg12:main Sep 14, 2026
1 check passed
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.

[FEATURE] Add batch processing for entire directories

2 participants