feat(research): preserve urban geometry pipelines and qualification suites

Preserve offline geometry, marking, replay and evaluation pipelines with source manifests and synthetic tests. Research qualification does not activate these methods as production navigation.
This commit is contained in:
DCCONSTRUCTIONS
2026-10-29 09:10:00 +03:00
parent 5d56237124
commit 69dc566665
611 changed files with 52016 additions and 28 deletions
@@ -0,0 +1,46 @@
"""Measure a stroke axis from its connected image ridge, before profile fitting.
This generates a proposal only. Every output still needs the unchanged two-view
body, flank, endpoint and ownership checks. No angle grid or reference map.
"""
import numpy as np
import cv2
from interval_profiles import strip
def measure(seed,readers):
if len(readers)!=2 or not .3<=seed['length']<=10.5:return seed,dict(reason='outside-local-stroke-scope')
origin,axis=seed['origin'],seed['axis'];normal=np.array([-axis[1],axis[0]])
step=.025
ts=np.arange(-seed['length']/2-.25,seed['length']/2+.251,step)
ns=np.arange(-.7,.701,step)
center=(abs(ts[:,None])<=seed['length']/2)&(abs(ns[None,:])<=.13)
fits=[]
for read in readers:
contrast,valid=strip(origin,axis,ts,ns,read)
values=contrast[center&valid]
if len(values)<5:return seed,dict(reason='unobserved-center')
level=float(np.quantile(values,.8))
if level<22:return seed,dict(reason='weak-center')
mask=(contrast>max(15.,.35*level))&valid
count,components,stats,_=cv2.connectedComponentsWithStats(mask.astype('uint8'),8)
touched=np.bincount(components[center&mask],minlength=count);touched[0]=0
index=int(touched.argmax())
if touched[index]<5:return seed,dict(reason='no-connected-ridge')
ii,jj=np.nonzero(components==index)
# A component cut by the measurement window has no measured extent.
if ii.min()==0 or ii.max()==len(ts)-1 or jj.min()==0 or jj.max()==len(ns)-1:return seed,dict(reason='component-clipped')
points=np.column_stack([ts[ii],ns[jj]])
weights=contrast[ii,jj].astype(float)
center_uv=np.average(points,axis=0,weights=weights)
covariance=(points-center_uv).T@((points-center_uv)*weights[:,None])/weights.sum()
vals,vecs=np.linalg.eigh(covariance);direction=vecs[:,-1]
if direction[0]<0:direction=-direction
if vals[-1]<4*max(vals[0],1e-9):return seed,dict(reason='non-elongated-ridge')
fits.append(dict(origin=origin+center_uv[0]*axis+center_uv[1]*normal,
axis=direction[0]*axis+direction[1]*normal,length=float(np.ptp((points-center_uv)@direction))+step))
angle=float(np.rad2deg(np.arccos(np.clip(abs(fits[0]['axis']@fits[1]['axis']),0,1))))
if angle>3 or np.linalg.norm(fits[0]['origin']-fits[1]['origin'])>.05:return seed,dict(reason='view-disagreement',angle_degrees=angle)
direction=fits[0]['axis']+fits[1]['axis'];direction/=np.linalg.norm(direction)
result={**seed,'origin':np.mean([r['origin']for r in fits],axis=0),'axis':direction,'length':float(np.mean([r['length']for r in fits]))}
return result,dict(reason='measured',angle_change_degrees=float(np.rad2deg(np.arccos(np.clip(abs(direction@axis),0,1)))),view_angle_degrees=angle)