#!/usr/bin/env python3 """Step 2: run Tesseract OCR (German) over a preprocessed receipt image, writing the raw recognized text to the output directory for inspection before it is handed to the structuring step.""" import argparse import os import pytesseract from PIL import Image def ocr(path: str, out_dir: str) -> str: os.makedirs(out_dir, exist_ok=True) img = Image.open(path) text = pytesseract.image_to_string(img, lang="deu", config="--psm 3") out_path = os.path.join(out_dir, "ocr.txt") with open(out_path, "w", encoding="utf-8") as f: f.write(text) return out_path def main(): parser = argparse.ArgumentParser() parser.add_argument("-in", dest="in_path", required=True) parser.add_argument("-out", dest="out_dir", required=True) args = parser.parse_args() out_path = ocr(args.in_path, args.out_dir) print(out_path) if __name__ == "__main__": main()