Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6da4dd5329 |
+35
-6
@@ -293,8 +293,42 @@ class LineShapeMatcher:
|
|||||||
kh=kh, kw=kw,
|
kh=kh, kw=kw,
|
||||||
cx_local=float(cx_local), cy_local=float(cy_local),
|
cx_local=float(cx_local), cy_local=float(cy_local),
|
||||||
))
|
))
|
||||||
|
self._dedup_variants()
|
||||||
return len(self.variants)
|
return len(self.variants)
|
||||||
|
|
||||||
|
def _dedup_variants(self) -> int:
|
||||||
|
"""Rimuove varianti con feature-set identico (post-quantizzazione).
|
||||||
|
|
||||||
|
Halcon-style: con angle range = (0, 360) e simmetrie del template,
|
||||||
|
molte rotazioni producono lo stesso set quantizzato di feature.
|
||||||
|
Es: quadrato a 0/90/180/270 deg → stesse features (modulo permutazione).
|
||||||
|
Hash su feature ordinate (livello 0, full-res) elimina i duplicati.
|
||||||
|
|
||||||
|
Vantaggio: meno varianti = meno chiamate kernel JIT al top-level
|
||||||
|
senza perdere copertura angolare effettiva. Per template asimmetrici
|
||||||
|
non rimuove nulla.
|
||||||
|
"""
|
||||||
|
seen: dict[bytes, int] = {}
|
||||||
|
kept: list[_Variant] = []
|
||||||
|
removed = 0
|
||||||
|
for var in self.variants:
|
||||||
|
lvl0 = var.levels[0]
|
||||||
|
order = np.lexsort((lvl0.bin, lvl0.dy, lvl0.dx))
|
||||||
|
key = (
|
||||||
|
lvl0.dx[order].tobytes()
|
||||||
|
+ b"|" + lvl0.dy[order].tobytes()
|
||||||
|
+ b"|" + lvl0.bin[order].tobytes()
|
||||||
|
+ b"|" + str(round(var.scale, 4)).encode()
|
||||||
|
)
|
||||||
|
h = key # diretto, senza hash crypto (collision ok solo se identici)
|
||||||
|
if h in seen:
|
||||||
|
removed += 1
|
||||||
|
continue
|
||||||
|
seen[h] = len(kept)
|
||||||
|
kept.append(var)
|
||||||
|
self.variants = kept
|
||||||
|
return removed
|
||||||
|
|
||||||
# --- Matching ------------------------------------------------------
|
# --- Matching ------------------------------------------------------
|
||||||
|
|
||||||
def _response_map(self, gray: np.ndarray) -> np.ndarray:
|
def _response_map(self, gray: np.ndarray) -> np.ndarray:
|
||||||
@@ -572,7 +606,6 @@ class LineShapeMatcher:
|
|||||||
subpixel: bool = True,
|
subpixel: bool = True,
|
||||||
verify_ncc: bool = True,
|
verify_ncc: bool = True,
|
||||||
verify_threshold: float = 0.4,
|
verify_threshold: float = 0.4,
|
||||||
ncc_skip_above: float = 0.85,
|
|
||||||
coarse_angle_factor: int = 2,
|
coarse_angle_factor: int = 2,
|
||||||
scale_penalty: float = 0.0,
|
scale_penalty: float = 0.0,
|
||||||
) -> list[Match]:
|
) -> list[Match]:
|
||||||
@@ -806,11 +839,7 @@ class LineShapeMatcher:
|
|||||||
search_radius=self.angle_step_deg / 2.0,
|
search_radius=self.angle_step_deg / 2.0,
|
||||||
original_score=score,
|
original_score=score,
|
||||||
)
|
)
|
||||||
# NCC verify lazy (Halcon-style): skip se shape-score gia molto
|
if verify_ncc:
|
||||||
# alto (probabilita falso positivo trascurabile). NCC e l'op
|
|
||||||
# piu costosa per match (warp + corr), quindi vale la pena
|
|
||||||
# saltarlo quando il gradiente shape e gia conclusivo.
|
|
||||||
if verify_ncc and float(score_f) < ncc_skip_above:
|
|
||||||
ncc = self._verify_ncc(gray0, cx_f, cy_f, ang_f, var.scale)
|
ncc = self._verify_ncc(gray0, cx_f, cy_f, ang_f, var.scale)
|
||||||
if ncc < verify_threshold:
|
if ncc < verify_threshold:
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user