"""
Test OCRModule — optical character recognition.
Requires: pip install pytesseract + tesseract binary installed.
  macOS:  brew install tesseract
  Ubuntu: sudo apt install tesseract-ocr
Requires webcam. Show text to the camera. Press 'q' to quit.
"""

import sys
sys.path.insert(0, '..')

import cvfiq


def main():
    print("=== OCR Reader Test ===")
    print("  Requires: pip install pytesseract + tesseract installed.")
    print("  Show printed text to the camera.")
    print("  Press 'q' to quit.")

    try:
        reader = cvfiq.ocr()
    except Exception as e:
        print(f"  OCR not available: {e}")
        print("  Install: pip install pytesseract")
        return

    with cvfiq.Camera(0, showFPS=True, title="OCR Test") as cam:
        for img in cam:
            texts, img = reader.findText(img)
            for t in texts:
                print(f"  [{t['confidence']:.0f}%] {t['text']}")
            cam.show(img)

    print("  PASSED")


if __name__ == "__main__":
    main()
