DXF compare: ancore ICP sul solo pezzo staccato dal bordo, errore ICP con motivo (#86)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jbf7qKuxsnAVjxthRy7dnB
This commit is contained in:
2026-10-24 13:54:25 +02:00
parent 88bba213e2
commit 11c7d2e98b
2 changed files with 74 additions and 3 deletions
+36
View File
@@ -21,6 +21,8 @@ from src.vision.costruttori import (
CALIBRATION_FILE,
DXF_FILE,
CostruttoreError,
_candidate_anchors,
_maschera_pezzo,
build_dxf_compare,
)
from src.vision.runner import run_graph
@@ -112,3 +114,37 @@ def test_dxf_illeggibile_solleva():
def test_parametri_ricetta_invalidi(kwargs):
with pytest.raises(CostruttoreError):
build_dxf_compare(a_scene(), SAMPLE_DXF.read_bytes(), **kwargs)
def test_maschera_pezzo_tiene_solo_il_blob_staccato_dal_bordo():
# #86: pezzo scuro staccato + rettangoli scuri attaccati al bordo + angolo nero
img = np.full((500, 600), 230, np.uint8)
img[200:300, 250:400] = 20 # il pezzo
img[0:60, 100:220] = 15 # attaccato al bordo alto
img[420:500, 300:420] = 15 # attaccato al bordo basso
img[0:80, 0:80] = 0 # angolo nero (borderValue=0 del raddrizzamento)
out = _maschera_pezzo(img, "dark", px_per_mm=4.0)
assert (out[200:300, 250:400] == 20).all() # il pezzo resta
assert (out[0:60, 100:220] == 255).all() # i rettangoli sono sfondo
assert (out[420:500, 300:420] == 255).all()
assert (out[0:80, 0:80] == 255).all() # angolo nero cancellato
def test_maschera_pezzo_senza_blob_staccato_solleva():
img = np.full((200, 200), 230, np.uint8)
img[:, 0:50] = 10 # solo una fascia attaccata al bordo
with pytest.raises(CostruttoreError, match="staccato dal bordo"):
_maschera_pezzo(img, "dark")
def test_ricetta_dxf_icp_fallito_riporta_il_motivo(monkeypatch, tmp_path):
# #86: l'errore "ICP fallito" porta il messaggio degli orientamenti caduti
from visionsuite.dxf.compare import DXFCompare
def boom(self, *a, **k):
raise ValueError("negative dimensions are not allowed")
monkeypatch.setattr(DXFCompare, "compare", boom)
with pytest.raises(CostruttoreError, match="ICP fallito.*negative dimensions"):
_candidate_anchors(a_scene(), SAMPLE_DXF, PX_PER_MM)