"""Compare matchers using spatially held-out AUTOMATIC matches, not human ground truth.""" import sys,json,time from pathlib import Path sys.path.insert(0,str(Path(__file__).resolve().parents[1])) import cv2,numpy as np from backend.experimental.matching import sift_matches,LearnedMatcher ROOT=Path(__file__).resolve().parents[1];OUT=ROOT/'private_benchmarks/research';OUT.mkdir(exist_ok=True) matcher=LearnedMatcher(ROOT/'models/loftr_outdoor.ckpt') rows=[] for name,fn in [('iris_sift',sift_matches),('loftr',matcher)]: for sample in range(1,7): folder=ROOT/'private_benchmarks/client_iris'/str(sample) a=cv2.imread(str(folder/'reference.png'));b=cv2.imread(str(folder/'moving.png'));start=time.perf_counter() dst,src=fn(a,b) row=dict(sample=sample,method=name,matches=len(src),seconds=round(time.perf_counter()-start,2)) np.savez_compressed(OUT/f'{sample}-{name}-matches.npz',reference=dst,moving=src) if len(src)>=16: hold=((dst[:,0]//150+dst[:,1]//150).astype(int)%5)==0 h,ins=cv2.findHomography(src[~hold],dst[~hold],cv2.USAC_MAGSAC,4) if h is not None and hold.any(): pred=cv2.perspectiveTransform(src[hold,None],h)[:,0];err=np.linalg.norm(pred-dst[hold],axis=1) row.update(train_inliers=int(ins.sum()),train_count=int((~hold).sum()),test_count=int(hold.sum()),heldout_median=float(np.median(err)),heldout_p95=float(np.percentile(err,95)),matrix=h.tolist()) rows.append(row);(OUT/'matchers.json').write_text(json.dumps(rows,indent=2));print(json.dumps(row),flush=True)