38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Test OCR on single image
|
|
"""
|
|
import sys
|
|
import os
|
|
|
|
def test_ocr(image_path):
|
|
print(f"Loading {image_path}...", file=sys.stderr)
|
|
try:
|
|
os.environ["DISABLE_MODEL_SOURCE_CHECK"] = "True"
|
|
from paddleocr import TextRecognition
|
|
text_rec = TextRecognition(model_name="PP-OCRv4_server_rec")
|
|
|
|
output = text_rec.predict(image_path, batch_size=1)
|
|
|
|
with open("ocr_debug.txt", "w", encoding="utf-8") as f:
|
|
f.write("Raw Output:\n")
|
|
if isinstance(output, list):
|
|
f.write(f"Output is list of length {len(output)}\n")
|
|
for i, res in enumerate(output):
|
|
f.write(f"Item {i} type: {type(res)}\n")
|
|
f.write(f"Item {i} dir: {dir(res)}\n")
|
|
f.write(f"Item {i} repr: {res}\n")
|
|
else:
|
|
f.write(f"Output type: {type(output)}\n")
|
|
f.write(str(output) + "\n")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}", file=sys.stderr)
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) < 2:
|
|
print("Usage: python test_ocr_single.py <image_path>")
|
|
sys.exit(1)
|
|
test_ocr(sys.argv[1])
|