merge: fix overlay shift
This commit is contained in:
@@ -1305,8 +1305,9 @@ class LineShapeMatcher:
|
|||||||
if t is None:
|
if t is None:
|
||||||
return 1.0
|
return 1.0
|
||||||
h, w = t.shape
|
h, w = t.shape
|
||||||
cx_t = (w - 1) / 2.0
|
# Coerente con training (center = diag / 2.0, no -1)
|
||||||
cy_t = (h - 1) / 2.0
|
cx_t = w / 2.0
|
||||||
|
cy_t = h / 2.0
|
||||||
|
|
||||||
# Bounding box del template ruotato/scalato attorno a (cx, cy)
|
# Bounding box del template ruotato/scalato attorno a (cx, cy)
|
||||||
diag = int(np.ceil(np.hypot(w, h) * scale)) + 8
|
diag = int(np.ceil(np.hypot(w, h) * scale)) + 8
|
||||||
|
|||||||
+9
-5
@@ -168,7 +168,10 @@ def _draw_matches(scene: np.ndarray, matches: list[Match],
|
|||||||
if template_gray is not None and matcher is not None:
|
if template_gray is not None and matcher is not None:
|
||||||
t = template_gray
|
t = template_gray
|
||||||
th, tw = t.shape
|
th, tw = t.shape
|
||||||
cx_t = (tw - 1) / 2.0; cy_t = (th - 1) / 2.0
|
# Centro template coerente col training: in train si usa
|
||||||
|
# `center = (diag / 2.0, diag / 2.0)` (no -1). Usare (tw-1)/2
|
||||||
|
# introduceva uno shift di 0.5px per template di lato pari.
|
||||||
|
cx_t = tw / 2.0; cy_t = th / 2.0
|
||||||
M = cv2.getRotationMatrix2D((cx_t, cy_t), m.angle_deg, m.scale)
|
M = cv2.getRotationMatrix2D((cx_t, cy_t), m.angle_deg, m.scale)
|
||||||
M[0, 2] += m.cx - cx_t
|
M[0, 2] += m.cx - cx_t
|
||||||
M[1, 2] += m.cy - cy_t
|
M[1, 2] += m.cy - cy_t
|
||||||
@@ -181,10 +184,11 @@ def _draw_matches(scene: np.ndarray, matches: list[Match],
|
|||||||
warped_mask = cv2.warpAffine(
|
warped_mask = cv2.warpAffine(
|
||||||
mask_src, M, (W_scene, H_scene),
|
mask_src, M, (W_scene, H_scene),
|
||||||
flags=cv2.INTER_NEAREST, borderValue=0)
|
flags=cv2.INTER_NEAREST, borderValue=0)
|
||||||
# Erode di spread_radius per scartare la fascia di transizione
|
# Erode minimo (3x3) per togliere SOLO artefatti border-padding
|
||||||
# bordo che produce gradient spurio
|
# (~1px di bordo nero da warpAffine borderValue=0). Erode piu'
|
||||||
er_k = max(3, 2 * matcher.spread_radius + 1)
|
# grande spostava visualmente l'edge verso l'interno e creava
|
||||||
kernel_er = np.ones((er_k, er_k), np.uint8)
|
# apparente "traslazione fissa" rispetto al bordo del pezzo.
|
||||||
|
kernel_er = np.ones((3, 3), np.uint8)
|
||||||
warped_mask = cv2.erode(warped_mask, kernel_er)
|
warped_mask = cv2.erode(warped_mask, kernel_er)
|
||||||
mag, _ = matcher._gradient(warped_gray)
|
mag, _ = matcher._gradient(warped_gray)
|
||||||
if matcher.weak_grad < matcher.strong_grad:
|
if matcher.weak_grad < matcher.strong_grad:
|
||||||
|
|||||||
Reference in New Issue
Block a user