"""Evaluate both matchers plus masked local refinement. Research only.""" 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.refinement import local_map from backend.experimental.preprocessing import iris_mask,glare_mask ROOT=Path(__file__).resolve().parents[1];OUT=ROOT/'private_benchmarks/research' rows=[] for rec in json.loads((OUT/'matchers.json').read_text()): n,method=rec['sample'],rec['method'];folder=OUT/f'{n}-{method}';folder.mkdir(exist_ok=True) row=dict(rec) if 'matrix' not in rec or rec.get('train_inliers',0)<12 or rec['train_inliers']/rec['train_count']<.3 or rec['test_count']<8: row['status']='insufficient evidence';rows.append(row);continue source=ROOT/'private_benchmarks/client_iris'/str(n) a=cv2.imread(str(source/'reference.png'));b=cv2.imread(str(source/'moving.png')) matrix=np.array(rec['matrix']);h,w=a.shape[:2] # Reject implausible global geometry before attempting to produce a preview. corners=np.float32([[0,0],[w,0],[w,h],[0,h]]) wc=cv2.perspectiveTransform(corners[None],matrix)[0] area=cv2.contourArea(wc,oriented=True)/(h*w) if not .520)&(gb>20) gain=float(np.clip(np.median(ga[clean]/np.maximum(gb[clean],1)),1,2.5)) adjusted=np.clip(aligned.astype(np.float32)*gain,0,255).astype(np.uint8) weight=(trust&clean).astype(np.float32)*.35 # Conservative baseline composite; no speculative reflection removal here. composite=np.rint(a*(1-weight[...,None])+adjusted*weight[...,None]).astype(np.uint8) outputs=dict(aligned=aligned,adjusted=adjusted,overlay=cv2.addWeighted(a,.5,adjusted,.5,0),composite=composite,confidence=trust.astype(np.uint8)*255,global_aligned=global_image) for key,value in outputs.items():cv2.imwrite(str(folder/(key+'.png')),value) np.savez_compressed(folder/'mapping.npz',map=mapping) row['exposure_gain']=gain rows.append(row);(OUT/'refinement.json').write_text(json.dumps(rows,indent=2));print(json.dumps(row),flush=True) (OUT/'refinement.json').write_text(json.dumps(rows,indent=2))