import cv2 import os import sys import json from paddleocr import PaddleOCR def run_sanity(): img_path = "seal_cropped.png" if not os.path.exists(img_path): print(f"Error: {img_path} not found") return img = cv2.imread(img_path) h, w = img.shape[:2] print(f"Image: {img_path}, Shape: {h}x{w}") ocr = PaddleOCR(use_angle_cls=True, lang='ch') # OCR on Raw raw_res = ocr.ocr(img_path) # Manual Unwarp cx, cy = w//2, h//2 radius = min(cx, cy) out_w = int(radius * 3.14 * 2) out_h = radius unwarped = cv2.warpPolar(img, (out_w, out_h), (cx, cy), radius, cv2.WARP_FILL_OUTLIERS + cv2.WARP_POLAR_LINEAR) unwarp_path = "debug_unwarp_sanity.png" cv2.imwrite(unwarp_path, unwarped) # OCR on Unwarp unwarp_res = ocr.ocr(unwarp_path) results = { "raw": str(raw_res), "unwarp": str(unwarp_res) } with open("sanity_results.json", "w", encoding="utf-8") as f: json.dump(results, f, ensure_ascii=False, indent=2) print("Sanity results saved to sanity_results.json") if __name__ == "__main__": run_sanity()