code wiki / _hdl_build / nx_svmetrology.nx
nx_svmetrology.nx
buildroot/runtime/_hdl_build/nx_svmetrology.nx
about
nx_svmetrology.nx -- THE MULTI-CUE SCALE SOLVER (debts 1785958292 + 1785957867; operator 2026-08-05:
"be clever but stay reproducible"). Single-view metrology done as an OVER-DETERMINED system.
THE DOCTRINE, IN CODE: never choose a reference. Every scale cue in a scene is an independent estimate
of ONE unknown (camera height, in micrometres), so N cues leave N-1 degrees of freedom of VALIDATION.
Fuse by inverse-variance weighting, then TEST the agreement with chi-square. Below threshold: report
the interval. Above: REFUSE and NAME THE OUTLIER -- averaging away a disagreement hides the broken
assumption that caused it (a partition is a claim; check the parts sum).
A SINGLE CUE IS NEVER VALIDATED: 0 dof means there is nothing to check it against, and the organ says
so out loud rather than reporting a confident number.
GEOMETRY (Criminisi/Reid/Zisserman single-view metrology): for a flat ground plane the horizon sits at
camera-optical-axis height, so for any object standing ON that plane, with no focal length needed:
h_obj / h_cam = (y_base - y_top) / (y_base - y_horizon)
LEVERAGE LAW (measured 2026-08-05): the error scales INVERSELY with (y_base - y_horizon), so a NEAR
reference beats a distant one however crisp the distant one looks. The organ reports that denominator
as `leverage_px` on every cue it derives, so a caller can see which reference is worth having.
nx_svmetrology camheight <y_base> <y_top> <y_horizon> <h_obj_um> <sigma_permil> -> one cue row
nx_svmetrology height <y_base> <y_top> <y_horizon> <h_cam_um> <sigma_permil> -> a height, given scale
nx_svmetrology fuse <cuefile> [max_reduced_chi2_x100] -> posterior + chi2 + residuals
nx_svmetrology selftest
CUE ROWS (tab-separated; the cue registry plane uses the same shape):
cue <TAB> <name> <TAB> <value_um> <TAB> <sigma_um> [<TAB> provenance [<TAB> source]]
license_tier: ORIGINAL expect_exit: 0
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 27 | const SV_MAGIC_2000: i64 = 2000 |
| 28 | const SV_MAGIC_1700000: i64 = 1700000 |
| 30 | const SV_CAP: i64 = 262144 |
| 31 | const SV_MAXCUE: i64 = 256 |
| 32 | const SV_WK: i64 = 1000000000000 |
| 33 | const SV_DEFCHI: i64 = 400 |
| 34 | const SV_TAB: i64 = 9 |
| 35 | const SV_NL: i64 = 10 |
functions
| 37 | func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 38 | func pn(v: i64) -> i64 { let b: *u8=sys_mmap(32) as *u8; var x: i64=v; var ng: i64=0; if x<0{ng=1;x=0-x} var i: i64=31; if x==0{b[i]=48 as u8;i=i-1} while x>0{b[i]=(48+x%10) as u8;x=x/10;i=i-1} if ng==1{b[i]=45 as u8;i=i-1} sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 } |
| 39 | func sv_pr(b: *u8, a: i64, e: i64) -> i64 { if e > a { sys_write(1, ((b as i64)+a) as *u8, e-a) } return 0 } |
| 40 | func sv_isqrt(x: i64) -> i64 called by 1: sv_fuse |
| 47 | func sv_refuse(reason: *u8) -> i64 { hw("SVMETROLOGY REFUSED: " as *u8); hw(reason); hw("\n" as *u8); return 0 } |
| 51 | func sv_eol(b: *u8, n: i64, i: i64) -> i64 called by 1: sv_fuse |
| 57 | func sv_cols(b: *u8, ls: i64, le: i64, col: *i64, maxc: i64) -> i64 called by 1: sv_fuse |
| 72 | func sv_int(b: *u8, a: i64, e: i64) -> i64 called by 1: sv_fuse |
| 85 | func sv_same(b: *u8, a: i64, e: i64, lit: *u8) -> i64 |
| 93 | func sv_argint(s: *u8) -> i64 called by 1: main |
| 106 | func sv_read(path: *u8, buf: *u8, cap: i64) -> i64 |
| 122 | func sv_camheight(yb: i64, yt: i64, yh: i64, hobj: i64, sigpm: i64) -> i64 |
| 144 | func sv_height(yb: i64, yt: i64, yh: i64, hcam: i64, sigpm: i64) -> i64 |
| 160 | func sv_fuse(buf: *u8, n: i64, maxchi: i64) -> i64 |
| 291 | func sv_wr(path: *u8, s: *u8) -> i64 |
| 300 | func sv_runfile(path: *u8, maxchi: i64) -> i64 |
| 306 | func sv_selftest() -> i64 |
| 339 | func main(argc: i64, argv: *i64) -> i64 |