report-detect/scripts/fix_polar_axes.py

47 lines
1.5 KiB
Python
Raw Normal View History

2026-02-05 13:57:22 +08:00
import cv2
import os
import numpy as np
def fix_polar_axes():
img_path = "seal_cropped.png"
img = cv2.imread(img_path)
if img is None: return
h_orig, w_orig = img.shape[:2]
cx, cy = w_orig // 2, h_orig // 2
radius = min(cx, cy)
# Target size for Theta (width) and Radius (height)
# Theta: 360 degrees -> we want high res, e.g. 1500 pixels
# Radius: 0 to radius -> 216 pixels
out_theta = 1500
out_r = radius
# Since warpPolar puts Radius on X and Theta on Y:
# We pass dsize = (out_r, out_theta)
unwarped = cv2.warpPolar(img, (out_r, out_theta), (cx, cy), radius, cv2.WARP_POLAR_LINEAR)
# Now unwarped has:
# Rows (y) = Theta
# Cols (x) = Radius
# We want a horizontal strip where X = Theta, Y = Radius
# So we transpose:
final = cv2.transpose(unwarped) # Now Rows = Radius, Cols = Theta
# Or better, just rotate 90 degrees?
# Actually transpose is what we want if (out_r, out_theta) was passed.
cv2.imwrite("fixed_polar_full.png", final)
# Extract outer annulus (Radius is now the vertical axis, 0 is center, max is edge)
# The text should be at the "bottom" part of the strip (high radius)
strip = final[int(out_r * 0.75):int(out_r * 0.95), :]
cv2.imwrite("fixed_polar_strip.png", strip)
print(f"Saved fixed_polar_full.png {final.shape}")
print(f"Saved fixed_polar_strip.png {strip.shape}")
if __name__ == "__main__":
fix_polar_axes()