report-detect/scripts/test_unwarp_schemes.py

42 lines
1.5 KiB
Python

import cv2
import numpy as np
import os
def test_schemes():
img_path = "seal_cropped.png"
img = cv2.imread(img_path)
if img is None:
print("Error: seal_cropped.png not found")
return
h, w = img.shape[:2]
cx, cy = w // 2, h // 2
radius = min(cx, cy)
# Scheme A: My current reproduce_java_flow logic
# out_w = radius * 2PI, height = outer 35%
out_w = int(radius * 2 * np.pi)
unwarped_a = cv2.warpPolar(img, (out_w, radius), (cx, cy), radius, cv2.WARP_POLAR_LINEAR)
strip_a = unwarped_a[int(radius*0.6):int(radius*0.95), :]
cv2.imwrite("test_scheme_A.png", strip_a)
# Scheme B: find_optimal_unwarp logic
# Rotate CCW, warp, keep outer 30% (indices 70%-100%), and FLIP
rotated_b = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE)
unwarped_b = cv2.warpPolar(rotated_b, (out_w, radius), (cx, cy), radius, cv2.WARP_POLAR_LINEAR)
strip_b = unwarped_b[int(radius*0.7):radius, :]
strip_b_final = cv2.flip(strip_b, 0)
cv2.imwrite("test_scheme_B.png", strip_b_final)
# Scheme C: Like B but with factor 5.0 (high width)
out_w_c = int(radius * 2 * np.pi * 5.0)
unwarped_c = cv2.warpPolar(rotated_b, (out_w_c, radius), (cx, cy), radius, cv2.WARP_POLAR_LINEAR)
strip_c = unwarped_c[int(radius*0.7):radius, :]
strip_c_final = cv2.flip(strip_c, 0)
cv2.imwrite("test_scheme_C.png", strip_c_final)
print("Schemes A, B, C saved for comparison.")
if __name__ == "__main__":
test_schemes()