diff --git a/app_ui.go b/app_ui.go index 65c7ec7..06db802 100644 --- a/app_ui.go +++ b/app_ui.go @@ -6585,6 +6585,13 @@ func (a *app) autoSetup(full bool) { return } next("Calibrate projector image") + fallbackScanRan := false + if a.st.Indoor { + logf("Auto setup Indoors: measuring stripes FIRST. No global fitting dots are projected on unknown furniture. A webcam image or object label alone cannot certify a flat plane; no flat-only dot guarantee is claimed for final verification markers.") + a.scanWithOwner(context.Background(),nil,false,acceptedOwner) + if cameraCommandSuperseded() || !a.calibrationOwnerCurrent(acceptedOwner) { return } + fallbackScanRan=true + } else { if full { a.calibrateModeMeasuredOwned("super", acceptedOwner) if cameraCommandSuperseded() || !a.calibrationOwnerCurrent(acceptedOwner) { @@ -6598,7 +6605,6 @@ func (a *app) autoSetup(full bool) { } // One adaptive dot run is the run. Do not repeat the entire calibration // just because the usable installed result is labelled BAD. - fallbackScanRan := false if !calibrationTrusted(a.pl.P) { if calibrationAccepted(a.pl.P) { @@ -6612,6 +6618,8 @@ func (a *app) autoSetup(full bool) { } fallbackScanRan = true } + } + if !calibrationAccepted(a.pl.P) { failedSteps = append(failedSteps, "Calibrate projector image (no accepted calibration - the scan could not carry the wall map either)") @@ -6632,7 +6640,7 @@ func (a *app) autoSetup(full bool) { } } - if a.st.Indoor && a.pl.P.Map.Mode == "camera" && len(a.pl.P.Map.Pairs) >= 6 { + if autoSurfaceDots355(a.st.Indoor, a.pl.P) { logf("Indoors: giving each surface its own calibration too.") a.calibrateSomeSurfacesOwned(nil, acceptedOwner) if cameraCommandSuperseded() || !a.calibrationOwnerCurrent(acceptedOwner) { @@ -6673,6 +6681,9 @@ func (a *app) autoSetup(full bool) { if vn > 0 && vat.After(runStart) { vnote = fmt.Sprintf(" Fresh independent map check: %.1f px average (worst %.1f) over %d markers.", vmean, vworst, vn) } + if vn != 12 || !vat.After(runStart) || !calibrationCheckGood355(vn, true, vmean, vworst) { + failedSteps = append(failedSteps, "Map verification (no fresh complete 12-marker check within 2 px average / 8 px worst; map remains UNVERIFIED)") + } if len(failedSteps) > 0 { uncalNote := "" if a.pl.P.UncalibratedShow { diff --git a/autocal_dense355_windows.go b/autocal_dense355_windows.go new file mode 100644 index 0000000..64f6ef2 --- /dev/null +++ b/autocal_dense355_windows.go @@ -0,0 +1,61 @@ +//go:build windows + +package main + +import "time" + +// Caller holds studioContextMu and a camera job. Freeze the files and verify +// those dense addresses, not an unrelated best-fit homography. +func (a *app) checkDenseCalibration355(owner *calibrationOwner, surfs []Surface) { + ref := *owner.project.Scan + res, binding, err := loadScanBound(&ref) + if err != nil { + logf("Dense calibration check: cannot load scan: %v; UNVERIFIED.", err) + return + } + if !fakeCam { + if _, err = startCamera(); err != nil { + logf("Dense calibration check: camera: %v; UNVERIFIED.", err) + return + } + } + defer func() { a.presMu.Lock(); pat.clear(); a.presTok = PatternToken{}; a.presMu.Unlock() }() + logf("Dense calibration check: measuring 12 fresh markers against saved pixel correspondence. This checks correspondence, not every renderer/compositor path.") + n, mean, worst, report, complete := verifyScanComplete355(winScanIO{}, res, surfs) + if !calibrationCheckGood355(n, complete, mean, worst) && complete && n < 12 { + logf("Dense calibration check: retrying once with 50%% larger fiducials for missing markers; dense addresses and quality thresholds unchanged.") + n, mean, worst, report, complete = verifyScanComplete355(largerFiducials355{}, res, surfs) + } + + for _, line := range report { + logf("Dense calibration check: %s", line) + } + if !calibrationCheckGood355(n, complete, mean, worst) { + logf("Dense calibration check: UNVERIFIED (complete=%v, %d/12 markers, average %.1f px, worst %.1f). Map unchanged.", complete, n, mean, worst) + return + } + if !verifyScanBinding(&ref, binding) { + logf("Dense calibration check: scan files changed; result discarded.") + return + } + if !a.publishCalibrationCheckOwned(owner, mean, worst, n) { + logf("Dense calibration check: destination changed; result discarded.") + return + } + logf("Dense calibration check: complete correspondence check, %.1f px average / %.1f worst, %d/12 markers. Not full physical renderer acceptance.", mean, worst, n) +} + +func (winScanIO) patternEstimate355(frames int) time.Duration { + camMu.Lock() + per := camPeriod + camMu.Unlock() + if per <= 0 { + per = time.Second / 15 + } + // Measured camera freshness plus frames consumed by settle/stability/average. + return freshMargin(per) + time.Duration(frames+7)*per + 200*time.Millisecond +} + +type largerFiducials355 struct{ winScanIO } + +func (largerFiducials355) Dots(p [][2]float64, r float64) { winScanIO{}.Dots(p, r*1.5) } diff --git a/autocal_truth355.go b/autocal_truth355.go new file mode 100644 index 0000000..20892eb --- /dev/null +++ b/autocal_truth355.go @@ -0,0 +1,32 @@ +package main + +import "math" + +// Dot probes cannot replace a dense scan's warp. Check the owner that will +// actually render, and never call a partial capture a verified calibration. +func autoSurfaceDots355(indoor bool, p *Project) bool { + return indoor && p != nil && p.Scan == nil && p.Map.Mode == "camera" && len(p.Map.Pairs) >= 6 +} +func calibrationCheckGood355(seen int, complete bool, mean, worst float64) bool { + return complete && seen == 12 && !math.IsNaN(mean+worst) && !math.IsInf(mean+worst, 0) && mean >= 0 && worst >= mean && mean <= 2 && worst <= 8 +} + +// Compare coverage with reachable camera pixels, not a whole-camera target +// the physical projector cannot illuminate. Exactly one changed-stripe retry. +func scanRetryNeeded355(decoded, confidence, reachable float64) bool { + if reachable <= 0 || reachable > 1 { + reachable = 1 + } + return decoded < 0.85*reachable || confidence < 70 +} +func scanRetryBits355(x, y int) (int, int) { + x-- + y-- + if x < 6 { + x = 6 + } + if y < 5 { + y = 5 + } + return x, y +} diff --git a/autocal_truth355_test.go b/autocal_truth355_test.go new file mode 100644 index 0000000..2ca7690 --- /dev/null +++ b/autocal_truth355_test.go @@ -0,0 +1,18 @@ +package main +import("testing";"math") +func TestCalibrationCheckTruth355(t *testing.T){ + for _,x:=range []struct{n int;complete bool;mean,worst float64;want bool}{{12,true,1,2,true},{5,true,1,2,false},{12,false,1,2,false},{12,true,5.2,7.9,false},{12,true,1,9,false},{12,true,math.NaN(),1,false},{12,true,1,math.Inf(1),false},{12,true,-1,1,false}}{ + if got:=calibrationCheckGood355(x.n,x.complete,x.mean,x.worst);got!=x.want{t.Fatalf("%+v got%v",x,got)} + } +} +func TestAdaptiveRetryReach355(t *testing.T){ + if scanRetryNeeded355(.28,97,.30){t.Fatal("repeats a good reachable area because whole camera stays dark")} + if !scanRetryNeeded355(.21,97,.30)||!scanRetryNeeded355(.28,60,.30)||!scanRetryNeeded355(0,0,.3){t.Fatal("no changed-stripe retry for poor capture")} + x,y:=scanRetryBits355(7,6);if x!=6||y!=5{t.Fatal(x,y)} + x,y=scanRetryBits355(1,1);if x!=6||y!=5{t.Fatal("unbounded coarse retry")} +} +func TestScanSkipsUnusedSurfaceDots355(t *testing.T){ + p:=&Project{};p.Map.Mode="camera";p.Map.Pairs=make([]Pair,6) + if !autoSurfaceDots355(true,p)||autoSurfaceDots355(false,p){t.Fatal("non-scan behavior changed")} + p.Scan=&ScanRef{};if autoSurfaceDots355(true,p){t.Fatal("scan ran unused surface dots")} +} diff --git a/calibcheckrun_win.go b/calibcheckrun_win.go index 5fae2d0..e41ef62 100644 --- a/calibcheckrun_win.go +++ b/calibcheckrun_win.go @@ -20,6 +20,13 @@ func (a *app) checkCalibrationOwned(owner *calibrationOwner) { return } defer calGuard("Calibration check")() + a.verifyMu.Lock() + a.verifyN,a.verifyMean,a.verifyWorst=0,0,0 + a.verifyAt=time.Time{} + a.verifyOwner=nil + a.verifyMu.Unlock() + if owner.project.Scan!=nil { scanMapUnverified.Store(true) } + if !a.projOpen && !fakeCam { logf("Check calibration needs the projector window. Click Open projector first.") return @@ -29,6 +36,10 @@ func (a *app) checkCalibrationOwned(owner *calibrationOwner) { surfs := append([]Surface(nil), a.pl.P.Surfaces...) a.pl.mu.Unlock() + if scanActiveFor(a.pl.P, m.ProjRes) { + a.checkDenseCalibration355(owner, surfs) + return + } rough := m.Mode == "manual" h, projToCam, okH := fiducialPredictor(m) @@ -77,6 +88,7 @@ func (a *app) checkCalibrationOwned(owner *calibrationOwner) { measured := make([][2]float64, len(grid)) ok := make([]bool, len(grid)) seen := 0 + complete := true capProgress(0) defer capProgressIdle() @@ -84,6 +96,7 @@ func (a *app) checkCalibrationOwned(owner *calibrationOwner) { capProgress(float64(i) / float64(len(grid))) if !showPatternAcked(io, PatternToken{Kind: "dots", Axis: -1, Bit: -1}, func() { io.Dots([][2]float64{p}, 0.006) }, vrun, &vseq, 400, 2, nil, vfail) { logf("Check calibration: the projector stopped painting fiducials - stopped early.") + complete = false break } g := io.Gray(3) @@ -96,6 +109,7 @@ func (a *app) checkCalibrationOwned(owner *calibrationOwner) { b := findBlob(d, &exp, 1.0/6.0, 30) if !showPatternAcked(io, PatternToken{Kind: "black", Axis: -1, Bit: -1}, io.Black, vrun, &vseq, 200, 2, nil, vfail) { logf("Check calibration: the projector stopped painting between fiducials - stopped early.") + complete = false break } if !b.OK { @@ -164,6 +178,10 @@ func (a *app) checkCalibrationOwned(owner *calibrationOwner) { a2 := by[n] logf("Check calibration: %s - %.1f px average over %d markers (worst %.1f)%s", n, a2.sum/float64(a2.n), a2.n, a2.worst, label) } + if !calibrationCheckGood355(seen, complete, mean, worst) { + logf("Check calibration: UNVERIFIED (complete=%v, %d/12 markers, average %.1f px, worst %.1f). No verified result published; mapping unchanged.", complete, seen, mean, worst) + return + } if !a.publishCalibrationCheckOwned(owner, mean, worst, seen) { logf("Check calibration: destination changed or stopped; fresh result discarded.") return @@ -175,7 +193,7 @@ func (a *app) checkCalibrationOwned(owner *calibrationOwner) { // Caller pins studio context. Keep stale measurements out of live status. func (a *app) publishCalibrationCheckOwned(owner *calibrationOwner, mean, worst float64, seen int) bool { - if owner == nil { + if owner == nil || !calibrationCheckGood355(seen, true, mean, worst) { return false } owner.player.mu.Lock() diff --git a/calibsurf.go b/calibsurf.go index 06d182d..2aafe26 100644 --- a/calibsurf.go +++ b/calibsurf.go @@ -39,6 +39,10 @@ func (a *app) calibrateSomeSurfacesOwned(only map[string]bool, owner *calibratio } } a.pl.mu.Unlock() + if scanActiveFor(a.pl.P, m.ProjRes) { + logf("Per-surface dots skipped: the dense scan owns the warp. Verify or re-run the scan instead; no unused dots were captured.") + return + } if len(surfs) == 0 { return } diff --git a/common.go b/common.go index 9142223..e0e36bd 100644 --- a/common.go +++ b/common.go @@ -11,7 +11,7 @@ import ( "time" ) -const version = "0.98.354-experimental1" +const version = "0.98.355-experimental1" const appDisplayName = "Projection Mapper - Built by Instinct" diff --git a/graycore.go b/graycore.go index 43cff3c..d775cd6 100644 --- a/graycore.go +++ b/graycore.go @@ -517,11 +517,13 @@ func runScanMode(io scanIO, mode scanMode, projW, projH, bitsX, bitsY, settle, f } } } - if mode == scanXOR { - io.Log("Scan: %d patterns (%d X + %d Y bits, XOR fast set), about %d seconds.", len(imgs), bitsX, bitsY, len(imgs)*(settle+120)/1000+4) - } else { - io.Log("Scan: %d patterns (%d X + %d Y bits, normal + inverse), about %d seconds.", len(imgs), bitsX, bitsY, len(imgs)*(settle+120)/1000+4) - } + label := "normal + inverse" + if mode == scanXOR { label = "XOR fast set" } + if timing,ok := io.(interface{patternEstimate355(int)time.Duration});ok { + io.Log("Scan: %d patterns (%d X + %d Y bits, %s); camera-timed estimate %.0f seconds, updated from completed captures.",len(imgs),bitsX,bitsY,label,(time.Duration(len(imgs)+2)*timing.patternEstimate355(frames)).Seconds()) + } else { io.Log("Scan: %d patterns (%d X + %d Y bits, %s); estimating after initial captures.",len(imgs),bitsX,bitsY,label) } + passStart355 := time.Now() + runID := time.Now().UnixNano() seq := 0 @@ -554,7 +556,7 @@ func runScanMode(io scanIO, mode scanMode, projW, projH, bitsX, bitsY, settle, f noteCapture() capProgress(float64(i+1) / float64(len(imgs))) if i%4 == 3 { - io.Log("Scan: %d of %d patterns captured...", i+1, len(imgs)) + io.Log("Scan: %d of %d patterns captured, elapsed %.0fs, measured remaining estimate %.0fs.", i+1, len(imgs), time.Since(passStart355).Seconds(), time.Since(passStart355).Seconds()*float64(len(imgs)-i-1)/float64(i+1)) } } io.Black() @@ -1399,7 +1401,10 @@ func surfaceForPoint(nx, ny float64, surfs []Surface) *Surface { return best } -func verifyScan(io scanIO, res *scanResult, surfs []Surface) (seen int, mean, worst float64, report []string) { +func verifyScan(io scanIO, res *scanResult, surfs []Surface) (int, float64, float64, []string) { + n,m,w,r,_ := verifyScanComplete355(io,res,surfs); return n,m,w,r +} +func verifyScanComplete355(io scanIO, res *scanResult, surfs []Surface) (seen int, mean, worst float64, report []string, complete bool) { grid := calibGridN(4, 3) surfErr := map[string][]float64{} var surfOrder []string @@ -1409,7 +1414,7 @@ func verifyScan(io scanIO, res *scanResult, surfs []Surface) (seen int, mean, wo vseq := 0 vfail := "Verify: the projector did not paint pattern %d (%s) after %d attempts." if !showPatternAcked(io, PatternToken{Kind: "black", Axis: -1, Bit: -1}, io.Black, vrun, &vseq, 400, 2, nil, vfail) { - return 0, 0, 0, []string{"the projector did not paint the black reference - check the projector window is open on the projector display"} + return 0, 0, 0, []string{"the projector did not paint the black reference - check the projector window is open on the projector display"}, false } base := io.Gray(3) @@ -1417,7 +1422,7 @@ func verifyScan(io scanIO, res *scanResult, surfs []Surface) (seen int, mean, wo for _, p := range grid { if !showPatternAcked(io, PatternToken{Kind: "dots", Axis: -1, Bit: -1}, func() { io.Dots([][2]float64{p}, 0.006) }, vrun, &vseq, 400, 2, nil, vfail) { report = append(report, "the projector stopped painting fiducials - verify stopped early") - return seen, mean, worst, report + if seen > 0 { mean /= float64(seen) }; return seen, mean, worst, report, false } g := io.Gray(3) d := diffImg(base, g) @@ -1435,7 +1440,7 @@ func verifyScan(io scanIO, res *scanResult, surfs []Surface) (seen int, mean, wo b := findBlob(d, &exp, 1.0/6.0, 30) if !showPatternAcked(io, PatternToken{Kind: "black", Axis: -1, Bit: -1}, io.Black, vrun, &vseq, 200, 2, nil, vfail) { report = append(report, "the projector stopped painting between fiducials - verify stopped early") - return seen, mean, worst, report + if seen > 0 { mean /= float64(seen) }; return seen, mean, worst, report, false } if !b.OK { report = append(report, fmt.Sprintf("fiducial %.2f,%.2f: not seen", p[0], p[1])) @@ -1487,11 +1492,11 @@ func verifyScan(io scanIO, res *scanResult, surfs []Surface) (seen int, mean, wo sm /= float64(len(es)) verdict := "good" if sm > 8 { - verdict = "loose - re-run the per-surface calibration on it" + verdict = "loose - re-run the dense scan" } report = append(report, fmt.Sprintf("surface %s: %d marker(s), avg %.1f px, worst %.1f px - %s", surfName[id], len(es), sm, wst, verdict)) } - return seen, mean, worst, report + return seen, mean, worst, report, true } func min(a, b int) int { diff --git a/player.go b/player.go index 35cbb28..5d1fb21 100644 --- a/player.go +++ b/player.go @@ -52,6 +52,7 @@ type Player struct { AvgMs float64 Frames uint64 SlowFr uint64 + calPatternFrame355 *Frame f1, f2 *Frame exportOwned bool frozen *Frame diff --git a/scanrun.go b/scanrun.go index 6505a72..ec728e9 100644 --- a/scanrun.go +++ b/scanrun.go @@ -511,9 +511,10 @@ func (a *app) scanWithOwner(ctx context.Context, continuation func(*camSession, } } - if res != nil && res.ValidFrac >= 0.05 && (res.MeanConf < 70 || res.ValidFrac < 0.45) { - logf("Scan: the first pass was noisy in places (confidence %.0f/255, %.0f%% decoded) - double-checking with a second pass.", res.MeanConf, 100*res.ValidFrac) - cap2 := runScanMode(winScanIO{}, mode, pw, ph, 0, 0, 300, 5, sess) + if res != nil && scanRetryNeeded355(res.ValidFrac, res.MeanConf, pf.Covered) { + retryX, retryY := scanRetryBits355(res.BitsX,res.BitsY) + logf("Scan: adaptive recovery, confidence %.0f/255, %.0f%% camera view decoded vs %.0f%% usable lit view. Retrying with wider %d/%d-bit stripes, same strict decode gates. Wider stripes trade precision for visibility; final verification still decides quality.",res.MeanConf,100*res.ValidFrac,100*pf.Covered,retryX,retryY) + cap2 := runScanMode(winScanIO{}, mode, pw, ph, retryX, retryY, 300, 5, sess) if cap2 != nil && cap2.White.W != 0 { if halfRes { cap2 = downscaleScanCap(cap2) @@ -598,7 +599,7 @@ func (a *app) scanWithOwner(ctx context.Context, continuation func(*camSession, logf("Scan: skipping the fine-pattern pass - it sharpens stripe reads, and this is a coarse gradient map.") } if !rampMode { - logf("Scan: refining with 12 fine patterns (about 15 seconds)...") + logf("Scan: refining with 12 fine patterns (camera-timed estimate %.0f seconds; actual time depends on pattern paint and stable frames)...",(12*(winScanIO{}).patternEstimate355(5)).Seconds()) var pcaps []gray32 planes, metas := phasePlanes(pw, ph, 64, 1.0) pseq := 0 @@ -819,7 +820,7 @@ func (a *app) scanVerify() { a.pl.mu.Lock() surfs := append([]Surface(nil), a.pl.P.Surfaces...) a.pl.mu.Unlock() - seen, mean, worst, report := verifyScan(winScanIO{}, res, surfs) + seen, mean, worst, report, complete := verifyScanComplete355(winScanIO{}, res, surfs) A.presMu.Lock() pat.clear() @@ -836,6 +837,12 @@ func (a *app) scanVerify() { logf("Verify: only %d of 12 markers were seen - treat the numbers below with suspicion.", seen) } + + if !calibrationCheckGood355(seen,complete,mean,worst) { + scanMapUnverified.Store(true) + logf("Verify: UNVERIFIED (complete=%v, %d/12 markers, %.1f px average, %.1f worst). No verified receipt saved.",complete,seen,mean,worst) + return + } calibStateMu.Lock() a.pl.mu.Lock() if a.pl.P.Scan != nil && a.pl.P.Scan.XFile == ref.XFile && a.pl.P.Scan.At == ref.At { diff --git a/showaudio_player_snapshot.go b/showaudio_player_snapshot.go index 651df38..fc5aee2 100644 --- a/showaudio_player_snapshot.go +++ b/showaudio_player_snapshot.go @@ -16,6 +16,15 @@ func (pl *Player) renderWithShowAudio(proofOn bool) (*Frame, showAudioReceipt) { pl.R.hoverLineage.Store(nil) } off := showAudioReceipt{SafetyDark: true} + // Patterns replace every output pixel. Do not render an expensive hidden + // scene before delivering the next camera-calibration pattern. + if patternLive.Load() { + w,h := pl.frameSize() + if pl.calPatternFrame355 == nil || pl.calPatternFrame355.W != w || pl.calPatternFrame355.H != h { pl.calPatternFrame355 = newFrame(w,h) } + clear(pl.calPatternFrame355.Pix) + pl.calPatternFrame355.renderedFX = nil + return pl.calPatternFrame355, off + } if f := pl.retiredVehicleDarkLocked(); f != nil { return f, off }