react-native-image-stitcher 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +511 -1
  2. package/README.md +1 -1
  3. package/android/src/main/cpp/keyframe_gate_jni.cpp +138 -0
  4. package/android/src/main/java/io/imagestitcher/rn/IncrementalStitcher.kt +412 -40
  5. package/android/src/main/java/io/imagestitcher/rn/KeyframeGate.kt +128 -0
  6. package/android/src/main/java/io/imagestitcher/rn/RNSARCameraView.kt +87 -45
  7. package/android/src/main/java/io/imagestitcher/rn/RNSARSession.kt +46 -4
  8. package/cpp/stitcher.cpp +101 -1
  9. package/cpp/stitcher.hpp +8 -0
  10. package/dist/camera/Camera.d.ts +9 -0
  11. package/dist/camera/Camera.js +165 -43
  12. package/dist/camera/CaptureDebugOverlay.d.ts +45 -0
  13. package/dist/camera/CaptureDebugOverlay.js +146 -0
  14. package/dist/camera/CaptureKeyframePill.d.ts +28 -0
  15. package/dist/camera/CaptureKeyframePill.js +60 -0
  16. package/dist/camera/CaptureMemoryPill.d.ts +28 -0
  17. package/dist/camera/CaptureMemoryPill.js +109 -0
  18. package/dist/camera/CaptureOrientationPill.d.ts +22 -0
  19. package/dist/camera/CaptureOrientationPill.js +44 -0
  20. package/dist/camera/CaptureStitchStatsToast.d.ts +45 -0
  21. package/dist/camera/CaptureStitchStatsToast.js +133 -0
  22. package/dist/camera/PanoramaSettings.d.ts +478 -0
  23. package/dist/camera/PanoramaSettings.js +120 -0
  24. package/dist/camera/PanoramaSettingsBridge.d.ts +84 -0
  25. package/dist/camera/PanoramaSettingsBridge.js +208 -0
  26. package/dist/camera/PanoramaSettingsModal.d.ts +50 -298
  27. package/dist/camera/PanoramaSettingsModal.js +189 -354
  28. package/dist/camera/buildPanoramaInitialSettings.d.ts +70 -0
  29. package/dist/camera/buildPanoramaInitialSettings.js +97 -0
  30. package/dist/camera/lowMemDevice.d.ts +24 -0
  31. package/dist/camera/lowMemDevice.js +69 -0
  32. package/dist/index.d.ts +16 -2
  33. package/dist/index.js +37 -2
  34. package/dist/sensors/useIMUTranslationGate.d.ts +26 -0
  35. package/dist/sensors/useIMUTranslationGate.js +83 -1
  36. package/dist/stitching/incremental.d.ts +25 -0
  37. package/dist/stitching/useIncrementalStitcher.d.ts +12 -1
  38. package/dist/stitching/useIncrementalStitcher.js +7 -1
  39. package/ios/Sources/RNImageStitcher/IncrementalStitcher.swift +321 -7
  40. package/ios/Sources/RNImageStitcher/IncrementalStitcherBridge.swift +8 -0
  41. package/ios/Sources/RNImageStitcher/KeyframeGate.swift +12 -0
  42. package/ios/Sources/RNImageStitcher/KeyframeGateBridge.h +13 -0
  43. package/ios/Sources/RNImageStitcher/KeyframeGateBridge.mm +15 -0
  44. package/ios/Sources/RNImageStitcher/OpenCVStitcher.h +1 -0
  45. package/ios/Sources/RNImageStitcher/OpenCVStitcher.mm +17 -4
  46. package/ios/Sources/RNImageStitcher/Stitcher.swift +6 -1
  47. package/package.json +6 -2
  48. package/src/camera/Camera.tsx +220 -54
  49. package/src/camera/CaptureDebugOverlay.tsx +180 -0
  50. package/src/camera/CaptureKeyframePill.tsx +77 -0
  51. package/src/camera/CaptureMemoryPill.tsx +96 -0
  52. package/src/camera/CaptureOrientationPill.tsx +57 -0
  53. package/src/camera/CaptureStitchStatsToast.tsx +155 -0
  54. package/src/camera/PanoramaSettings.ts +605 -0
  55. package/src/camera/PanoramaSettingsBridge.ts +238 -0
  56. package/src/camera/PanoramaSettingsModal.tsx +296 -988
  57. package/src/camera/__tests__/PanoramaSettingsBridge.test.ts +375 -0
  58. package/src/camera/__tests__/buildPanoramaInitialSettings.test.ts +119 -0
  59. package/src/camera/__tests__/lowMemDevice.test.ts +52 -0
  60. package/src/camera/buildPanoramaInitialSettings.ts +139 -0
  61. package/src/camera/lowMemDevice.ts +71 -0
  62. package/src/index.ts +61 -3
  63. package/src/sensors/useIMUTranslationGate.ts +112 -1
  64. package/src/stitching/incremental.ts +25 -0
  65. package/src/stitching/useIncrementalStitcher.ts +18 -0
@@ -1,26 +1,61 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  /**
3
- * PanoramaSettingsModal — runtime A/B testing surface for the
4
- * stitcher pipeline. Operators in the field can toggle warper,
5
- * blender, and tuning constants between captures to see what
6
- * looks best on real shelf scenes.
3
+ * PanoramaSettingsModal — runtime tuning surface for <Camera>'s
4
+ * batch-keyframe panorama capture.
7
5
  *
8
- * The modal is presentational: the host owns the settings state
9
- * (typically `useState<PanoramaSettings>`) and renders the modal
10
- * with `visible` toggled by a gear-icon press in the capture
11
- * header. Settings flow OUT via `onChange` for each tweak.
6
+ * v0.4 rewrite (Phase 2 of F10):
7
+ * ──────────────────────────────
12
8
  *
13
- * Why expose this as an SDK component instead of leaving it to
14
- * each host? The set of tunable knobs IS the SDK's contract
15
- * if a new setting is added (e.g. registration MP) the SDK ships
16
- * the UI for it in lockstep with the param itself, instead of
17
- * forcing every host app to update its settings screen.
9
+ * The v0.3 modal exposed a flat 45-field surface that mixed
10
+ * batch-keyframe knobs with slit-scan, hybrid, and video-recording
11
+ * fallback fields the engine never reads in <Camera>'s
12
+ * `engine: 'batch-keyframe'` path. The 2026-05-22 audit (v0.3.0
13
+ * CHANGELOG) traced every field's native consumer and proved most of
14
+ * the cross-engine fields were dead surface in this modal.
15
+ *
16
+ * v0.4 narrows the modal to exactly the surface <Camera> consumes:
17
+ * the `PanoramaSettings` type defined in `./PanoramaSettings.ts`. Each
18
+ * section in the modal mirrors a sub-tree of that type — operators see
19
+ * the same shape in the UI as the code, and host apps that want to
20
+ * tune slit-scan or hybrid engines build their own analogous
21
+ * SlitscanSettingsModal / HybridSettingsModal on top of those types.
22
+ *
23
+ * UI structure (matches the type tree):
24
+ *
25
+ * - Debug (top-level, `debug`)
26
+ * - Frame selection (`frameSelection`, closed by default)
27
+ * - Mode
28
+ * - Max keyframes
29
+ * - Overlap threshold
30
+ * - Flow tunables (`frameSelection.flow`, only when
31
+ * mode === 'flow-based')
32
+ * - Max corners
33
+ * - Quality level
34
+ * - Min distance
35
+ * - Max translation cm
36
+ * - Novelty percentile
37
+ * - Eval every N frames
38
+ * - Stitcher (`stitcher`, closed by default)
39
+ * - Stitch mode
40
+ * - Warper type
41
+ * - Blender
42
+ * - Seam finder
43
+ * - Inscribed-rect crop
44
+ * - Reset to defaults (button)
45
+ *
46
+ * Note: `captureSource` (AR vs non-AR) is NOT surfaced here. The
47
+ * camera-screen AR toggle owns that state — Camera.tsx overrides the
48
+ * native bridge's `captureSource` with the derived
49
+ * `effectiveCaptureSource` so settings and runtime stay in sync.
50
+ *
51
+ * The reusable `Accordion` + `SectionHeader` + `SegmentedControl` +
52
+ * `Tag` helpers from the v0.3 modal are preserved verbatim — only the
53
+ * data-binding layer changed.
18
54
  */
19
55
 
20
56
  import React, { useState } from 'react';
21
57
  import {
22
58
  Modal,
23
- NativeModules,
24
59
  Pressable,
25
60
  ScrollView,
26
61
  StyleSheet,
@@ -28,489 +63,32 @@ import {
28
63
  View,
29
64
  } from 'react-native';
30
65
 
31
-
32
- export interface PanoramaSettings {
33
- warperType: 'plane' | 'cylindrical' | 'spherical';
34
- blenderType: 'multiband' | 'feather';
35
- /**
36
- * Seam finder strategy. "graphcut" finds optimal seams before
37
- * blending (cleaner output, pairs with multiband, more memory).
38
- * "skip" streams warp+feed (lower peak memory, fine with feather).
39
- */
40
- seamFinderType: 'graphcut' | 'skip';
41
- /**
42
- * V16 Phase 1b.fix5c (Ram's call 2026-05-10) — toggle the
43
- * max-inscribed-rectangle crop on the batch-keyframe output
44
- * panorama. When false (default), the output is cropped to the
45
- * bounding rectangle of non-black pixels only (cv::boundingRect)
46
- * — preserves all stitched content at the cost of some black
47
- * corners where cv::Stitcher's projection didn't fill. When
48
- * true, the post-stitch pipeline additionally runs
49
- * `MaxInscribedRectFromMask` to find the largest axis-aligned
50
- * rectangle entirely inside content, followed by the
51
- * column-projection second-pass. Inscribed-rect can be
52
- * over-aggressive on lopsided masks (field log showed a
53
- * 1146×1102 bbox shrinking to a 602×1102 strip), so default OFF
54
- * lets the operator see the full stitched scene; flip ON to
55
- * A/B against the cleaner-but-smaller output.
56
- */
57
- enableMaxInscribedRectCrop: boolean;
58
- /**
59
- * Phase 4.4 EXPERIMENTAL: when true, the host swaps the
60
- * vision-camera-backed CameraView for an ARKit-backed ARCameraView
61
- * during panorama capture. Default false (keeps the existing
62
- * stitcher flow untouched). Phase 5 will add AR-backed photo /
63
- * video capture and pose-driven stitching; until then this is
64
- * preview-only — useful for verifying the AR session renders
65
- * cleanly on the operator's device before we cut over.
66
- */
67
- useARPreview: boolean;
68
- /**
69
- * V15 — Incremental engine choice for live realtime stitching.
70
- * 'hybrid' — Whole-frame projection + feature matching;
71
- * planar by default (was cylindrical).
72
- * 'slitscan-rotate' — V13.0a baseline + 1D NCC for rotation
73
- * wobble correction.
74
- * 'slitscan-both' — DEFAULT. V13.0a + no accept gate +
75
- * feather blend. Iterate via per-stage
76
- * toggles below.
77
- *
78
- * All three are A/B-comparable on the same scene by toggling here
79
- * without restarting the app.
80
- */
81
- incrementalEngine:
82
- | 'batch-keyframe'
83
- | 'hybrid'
84
- | 'slitscan-rotate'
85
- | 'slitscan-both';
86
-
87
- /**
88
- * V15 — Slit-scan slit width (fraction of pan-axis retained per
89
- * frame). Range 0.10 – 0.70. Smaller = less within-slit multi-
90
- * depth disagreement but tighter overlap budget at fast pans.
91
- * Default 0.30. Only applied to slitscan-* engines.
92
- */
93
- slitWidthFraction: number;
94
-
95
- /**
96
- * V15 — Per-stage correction toggles for slitscan-both. Settings
97
- * UI exposes these so iteration happens via toggles, not rebuilds.
98
- */
99
- acceptGate: 0 | 50;
100
- enableTriangulation: boolean;
101
- enableTriAccumulator: boolean;
102
- enable2dNcc: boolean;
103
- enableRansacHomography: boolean;
104
- paintMode: 'FirstPaintedWins' | 'FeatherBlend';
105
- hybridProjection: 'Cylindrical' | 'Planar';
106
- /** 1D NCC search radius (slitscan-rotate only). */
107
- nccSearchRadius1d: number;
108
- /** **DEPRECATED in V15.0d** — see `planeSource`. Kept on the type
109
- * for backward compat with stored settings. When `planeSource`
110
- * is 'Disabled' (default) and this is true, the engine treats it
111
- * as 'ARKitDetected'. */
112
- useDetectedPlane: boolean;
113
- /** V15.0d — source of the plane used by the V15.0b plane-projected
114
- * stitch path. Slit-scan modes only.
115
- *
116
- * - 'Disabled': no plane projection (plain slit-scan).
117
- * - 'ARKitDetected': use ARKit's first vertical plane that aligns
118
- * with the camera's view direction. Falls back to slit-scan
119
- * silently when no aligned plane is found.
120
- * - 'Virtual': synthesize a plane perpendicular to the camera at
121
- * `virtualPlaneDepthMeters` distance. Always works; loses
122
- * "real depth" advantage but immune to ARKit picking the wrong
123
- * surface (which is the common failure mode for ARKitDetected). */
124
- planeSource: 'Disabled' | 'ARKitDetected' | 'Virtual';
125
- /** V15.0d — depth (m) of the synthetic plane in front of the camera
126
- * when `planeSource = 'Virtual'`. 0.3 – 5.0 m. Default 1.5 m. */
127
- virtualPlaneDepthMeters: number;
128
- /** V15.0d — alignment threshold (cosine) for ARKit-detected planes.
129
- * Higher = stricter (fewer planes accepted). 0.0 – 1.0.
130
- * Default 0.6 (≈53° max angle off-camera). */
131
- arkitPlaneAlignmentThreshold: number;
132
- /** V15.0g — plane-projection rendering style. Trapezoidal is the
133
- * V15.0b legacy 3D-correct mapping; Rectified is V15.0g's clean-
134
- * rectangle paste that eliminates tilt-induced trapezoidal
135
- * distortion. Default Rectified. Ignored when planeSource =
136
- * Disabled. */
137
- planeProjectionStyle: 'Trapezoidal' | 'Rectified';
138
- /** V15.0d — 2D NCC search half-window in pixels. 4 – 30.
139
- * Default 12. */
140
- nccSearchMargin2d: number;
141
- /** V15.0d — 2D NCC confidence threshold below which corrections
142
- * are rejected. 0.30 – 0.99. Default 0.75. */
143
- nccConfidenceThreshold2d: number;
144
- /** V15.0d (1B) — EMA smoothing on 2D NCC corrections to damp
145
- * single-frame snaps. Default false. */
146
- enableNcc2dEmaSmoothing: boolean;
147
- /** V15.0d — EMA weight on the CURRENT-frame correction. 0.05 – 0.95.
148
- * Default 0.4 (60% prev / 40% current). */
149
- ncc2dEmaAlpha: number;
150
- /** V15.0d (1C) — pan-axis-aware 2D NCC: clamp the cross-axis
151
- * correction tighter than the pan-axis. Default false. */
152
- enableNcc2dPanAxisLock: boolean;
153
- /** V15.0d — cross-axis clamp (px) when pan-axis lock is on.
154
- * 0 – 30. Default 5. */
155
- ncc2dCrossAxisLockPx: number;
156
-
157
- /** V16 — frame-selection mode for the live engine.
158
- *
159
- * - 'time-based' (default): every ARFrame is forwarded to the
160
- * engine; the engine's own gate (kMinAcceptDeltaPx etc.) decides.
161
- * Backward-compatible with all prior versions.
162
- * - 'pose-based': frames are pre-filtered by a KeyframeGate that
163
- * projects each onto the latched ARKit plane and accepts only
164
- * when overlap with the previous keyframe is < 1 −
165
- * overlapThreshold. Bounded to keyframeMaxCount frames per
166
- * capture (matches iOS Camera / Samsung Pano architecture).
167
- * Requires planeSource != 'Disabled' to engage.
168
- * - 'flow-based' (V16 A2, DEFAULT): same KeyframeGate cap +
169
- * threshold but the novelty metric is sparse-Lucas-Kanade
170
- * optical flow on full-frame content instead of plane-projected
171
- * polygon overlap. Plane-independent (scale-invariant — works
172
- * regardless of latched plane size); the metric is "median
173
- * pan-axis feature displacement / pan-axis frame dim", which is
174
- * a direct measure of % new content on the leading edge. Falls
175
- * back to angular delta when feature tracking fails (texture-
176
- * poor scene / motion exceeds KLT pyramid window). */
177
- frameSelectionMode: 'time-based' | 'pose-based' | 'flow-based';
178
- /** V16 — required NEW-content fraction for a keyframe to be
179
- * accepted (pose-based AND flow-based modes share this knob;
180
- * both interpret 0.40 as "40 % new content"). Tuneable from
181
- * 0.20 to 0.60 in the modal. */
182
- keyframeOverlapThreshold: number;
183
- /** V16 — hard cap on keyframes per capture (pose-based + flow-
184
- * based modes). Default 6. Once reached, all further frames are
185
- * rejected and the host should auto-finalize. */
186
- keyframeMaxCount: number;
187
- /** V16 A2 — flow-based mode: max Shi-Tomasi corners to detect per
188
- * accepted keyframe. More = more robust median pan-axis
189
- * displacement but slower detect (~15-25 ms at 150 on iPhone 13
190
- * Pro). Range 50 – 300, default 150. */
191
- flowMaxCorners: number;
192
- /** V16 A2 — flow-based mode: Shi-Tomasi quality level (0, 1].
193
- * Lower = more (weaker) corners detected; higher = fewer
194
- * (stronger) corners. Default 0.01. Range 0.005 – 0.05 in the
195
- * modal. */
196
- flowQualityLevel: number;
197
- /** V16 A2 — flow-based mode: minimum pixel distance between
198
- * detected corners at WORKING resolution (the gate internally
199
- * downscales the frame to 720 px longest side for KLT). Higher
200
- * = more spatially-spread features. Default 10. */
201
- flowMinDistance: number;
202
- /** V16 — flow-based mode: translation budget in CENTIMETRES.
203
- * When > 0, the gate force-accepts a frame if the camera has
204
- * translated more than this distance (3D Euclidean) since the
205
- * last accepted keyframe — even when novelty < threshold.
206
- * Bounds the parallax between adjacent keyframes so the
207
- * downstream affine stitcher matcher can fit a homography.
208
- * Range 0 – 100 cm in the modal, default 0 = disabled.
209
- * Recommended starting value once enabled: 8 cm. */
210
- flowMaxTranslationCm: number;
211
- /** V16 — flow-based mode: percentile used to aggregate tracked-
212
- * feature absolute displacements into the novelty estimate.
213
- * Pre-V16 used median (0.50); 0.85 picks up leading-edge
214
- * motion sooner — matches user perception of "new content
215
- * visible" better. Range 0.50 – 0.99, default 0.85. */
216
- flowNoveltyPercentile: number;
217
- /** V16 — flow-based mode: eval-throttle. Gate evaluation runs
218
- * every Nth consumeFrame from the AR delegate instead of every
219
- * frame. Pure CPU/battery savings — doesn't change WHICH
220
- * frames are accepted, just samples less frequently. Range
221
- * 1 – 10, default 1 (every frame). */
222
- flowEvalEveryNFrames: number;
223
-
224
- /** V15.0c — sliver position within the camera frame. 'Center' is
225
- * V13.x default. 'Bottom' takes leading-edge content for top-to-
226
- * bottom pan; 'Top' for bottom-to-top pan. */
227
- sliverPosition: 'Center' | 'Bottom' | 'Top';
228
- /** V15.0c — paint full first frame, then add slivers as user pans.
229
- * Useful with 'Bottom' or 'Top' sliverPosition. */
230
- firstFrameFullFrame: boolean;
231
- /** Hard cap on hold duration (ms). 0 disables auto-stop. */
232
- maxRecordingMs: number;
233
- /** Frames per second of recording to sample for stitching. */
234
- framesPerSecond: number;
235
- /** Floor / ceiling on extracted frame count. */
236
- minFrames: number;
237
- maxFrames: number;
238
- /** JPEG quality (0-100) for output panorama. */
239
- quality: number;
240
-
241
- // ── 2026-05-14: capture-source + stitch-mode axes ─────────────────
242
- //
243
- // These two settings are independent from the existing
244
- // `incrementalEngine` / `useARPreview` axes; together they decide
245
- // (a) which camera + tracking the capture screen uses, and (b)
246
- // which OpenCV pipeline mode the batch stitcher uses at finalize.
247
-
248
- /**
249
- * 2026-05-14 (revised) — capture-source picker for the panorama
250
- * camera screen. Two options after the 2026-05-14 user-reported
251
- * Galaxy A35 crash + simplification request:
252
- *
253
- * 'ar' (DEFAULT) — Use the AR stack (ARKit on iOS, ARCore on
254
- * Android). Plane detection, pose-aware
255
- * capture, pose-driven gate. Falls back to
256
- * non-AR silently if the device doesn't
257
- * support AR.
258
- * 'non-ar' — Use vision-camera. Disables all AR-based
259
- * services (planeSource=Disabled, no plane
260
- * polling, no AR session, frameSelectionMode
261
- * flipped to flow-based). Lens-switcher chip
262
- * on the capture screen lets the operator
263
- * toggle 0.5× / 1× without re-opening Settings.
264
- * The chip is hidden if the device has only
265
- * one physical back lens.
266
- *
267
- * Cascade: switching from 'ar' → 'non-ar' triggers a useEffect
268
- * in `AuditCaptureScreen` that patches dependent settings
269
- * (planeSource, frameSelectionMode, useARPreview) to a coherent
270
- * non-AR state. Operators don't have to know which other
271
- * settings to flip.
272
- *
273
- * Earlier draft (replaced 2026-05-14) had 4 values:
274
- * 'auto' | 'ar' | 'wide' | 'ultrawide'. The pre-mount
275
- * physical-lens selection ('wide' / 'ultrawide') crashed the
276
- * Galaxy A35 vision-camera CameraCaptureSession with a Parcel
277
- * exception (physical_camera_id=null in AidlCamera3-Device
278
- * configureStreams) — Camera2 can't be reliably steered to a
279
- * specific physical lens via vision-camera's `physicalDevices`
280
- * filter on this hardware. The post-mount on-screen chip path
281
- * works because vision-camera selects the safe multi-lens
282
- * virtual device first, and the lens swap happens against an
283
- * already-open camera.
284
- */
285
- captureSource: 'ar' | 'non-ar';
286
-
287
- /**
288
- * 2026-05-16 (Issue 5) — diagnostic toast on every successful
289
- * finalize. When `true`, the host renders a transient toast
290
- * summarising the C+D progressive-confidence retry telemetry:
291
- *
292
- * "Stitch: 6/6 frames retained at thresh 1.00 (1 attempt)"
293
- *
294
- * Defaults to `false` so end-users don't see it. Toggle from the
295
- * Settings modal under "Debug". Independent from any log-level
296
- * controls — purely a UI affordance for field testing.
297
- */
298
- debug: boolean;
299
-
300
- /**
301
- * 2026-05-14 — `cv::Stitcher` pipeline mode for the batch stitch.
302
- *
303
- * 'auto' (DEFAULT)
304
- * The capture engine looks at the accumulated translation vs
305
- * rotation magnitudes between first and last accepted keyframe
306
- * poses (AR-mode) or the windowed IMU integration (non-AR
307
- * mode) and picks PANORAMA or SCANS at finalize time.
308
- *
309
- * 'panorama'
310
- * `cv::Stitcher::PANORAMA` — rotation-only pipeline. Best for
311
- * "rotate phone in place to capture a wide field of view"
312
- * captures. ORB feature matching + global BundleAdjusterRay +
313
- * SphericalWarper. Sharp seams, expensive memory. WARNING:
314
- * on translation-heavy input the rotation-only homography fit
315
- * diverges and the canvas can blow up to multi-GB on Android
316
- * (2026-05-14 lmkd kill observed). Pick this only for genuine
317
- * rotation panoramas.
318
- *
319
- * 'scans'
320
- * `cv::Stitcher::SCANS` — translational pipeline. Best for
321
- * "walk past a shelf and pan sideways" captures. Affine
322
- * matcher + AffineBasedEstimator + BundleAdjusterAffine +
323
- * PlaneWarper. Canvas size bounded by sum of frame areas.
324
- * Slight quality drop on pure rotations but works for them too.
325
- *
326
- * iOS NOTE: as of 2026-05-14 the iOS stitcher uses a hand-rolled
327
- * PANORAMA-style pipeline (OpenCVStitcher.mm:600+) regardless of
328
- * this setting. Setting is passed through to iOS but ignored.
329
- * Android honours it via image_stitcher_jni.cpp. Bridging iOS is
330
- * a follow-up.
331
- */
332
- stitchMode: 'auto' | 'panorama' | 'scans';
333
- }
334
-
335
-
336
- // Per-device default selection. We read the iPhone's physical
337
- // RAM at SDK module load (exposed by `BatchStitcher`'s
338
- // `constantsToExport`) and pick the heaviest blender + seam
339
- // finder combo that fits. Threshold (2 GB) is conservative —
340
- // iPhone 6s through iPhone X have 2 GB exactly; below that
341
- // (iPhone 6 / 5s) is unsupported by RN 0.84 anyway. The user
342
- // can still flip ANY of these in the settings modal at runtime;
343
- // this only chooses the INITIAL default.
344
- const _physicalMemoryBytes: number = (() => {
345
- const m = (NativeModules as Record<string, unknown>).BatchStitcher;
346
- const bytes =
347
- m && typeof m === 'object'
348
- ? (m as { physicalMemoryBytes?: number }).physicalMemoryBytes
349
- : undefined;
350
- return typeof bytes === 'number' ? bytes : 0;
351
- })();
352
-
353
- const _isLowMem = _physicalMemoryBytes > 0
354
- && _physicalMemoryBytes < 2 * 1024 * 1024 * 1024;
355
-
356
- // One-line diagnostic so the host's Metro console shows what the
357
- // SDK saw at module load. If `physicalMemoryBytes=0` here, the
358
- // native bridge's `constantsToExport` isn't being picked up by
359
- // React Native and we should investigate the @objc registration.
360
- // The defaults always pick the SAFE fallback (multiband+graphcut)
361
- // when the value is 0 — this log is the only signal we have.
362
- // eslint-disable-next-line no-console
363
- console.log(
364
- '[capture-sdk] PanoramaSettings defaults: '
365
- + `physicalMemoryBytes=${_physicalMemoryBytes} `
366
- + `isLowMem=${_isLowMem} `
367
- + `→ blender=${_isLowMem ? 'feather' : 'multiband'} `
368
- + `seam=${_isLowMem ? 'skip' : 'graphcut'}`,
369
- );
66
+ import {
67
+ DEFAULT_FLOW_GATE_SETTINGS,
68
+ DEFAULT_PANORAMA_SETTINGS,
69
+ type BatchStitcherSettings,
70
+ type CaptureBaseSettings,
71
+ type FlowGateSettings,
72
+ type FrameSelectionSettings,
73
+ type PanoramaSettings,
74
+ } from './PanoramaSettings';
75
+ import {
76
+ getPhysicalMemoryBytes,
77
+ isLowMemDevice,
78
+ } from './lowMemDevice';
370
79
 
371
80
 
372
- export const DEFAULT_PANORAMA_SETTINGS: PanoramaSettings = {
373
- warperType: 'plane',
374
- // High-quality defaults on devices with ≥2 GB RAM (iPhone X+):
375
- // MultiBandBlender + GraphCutSeamFinder, the same combo
376
- // cv::Stitcher::PANORAMA uses internally and what produced the
377
- // sharpest output during iteration.
378
- // Low-memory devices (<2 GB) fall back to FeatherBlender + skip
379
- // seam (streams warp+feed) so peak memory stays under the
380
- // tighter jetsam threshold. Either way, the user can switch
381
- // both in the settings modal.
382
- blenderType: _isLowMem ? 'feather' : 'multiband',
383
- seamFinderType: _isLowMem ? 'skip' : 'graphcut',
384
- // V16 Phase 1b.fix5c — default OFF. See PanoramaSettings.enableMaxInscribedRectCrop.
385
- enableMaxInscribedRectCrop: false,
386
- // AR-backed capture is the default — vision-camera path is kept as
387
- // a fallback while we shake out edge cases.
388
- useARPreview: true,
389
- // V16 Phase 1 — batch-keyframe is the new default-recommended
390
- // engine: KeyframeGate caps input at ≤ keyframeMaxCount frames,
391
- // OpenCVStitcher's BA + GraphCut + ExposureCompensator +
392
- // MultiBandBlender runs once on shutter release. Existing
393
- // slitscan-* engines remain available for wide-pan fallback.
394
- incrementalEngine: 'batch-keyframe',
395
- slitWidthFraction: 0.30,
396
- acceptGate: 0,
397
- enableTriangulation: false,
398
- enableTriAccumulator: false,
399
- enable2dNcc: false,
400
- enableRansacHomography: false,
401
- // V15.0c — Ram observation: FirstPaintedWins is consistently the best
402
- // output across all combinations. Default switched from FeatherBlend.
403
- paintMode: 'FirstPaintedWins',
404
- hybridProjection: 'Planar',
405
- nccSearchRadius1d: 15,
406
- useDetectedPlane: false,
407
- // V16 Phase 1 — Virtual plane is the default since batch-keyframe
408
- // is the recommended engine and the gate needs a plane to compute
409
- // polygon overlap. Virtual works without ARKit-detected planes (a
410
- // synthesized plane perpendicular to the first-frame camera at
411
- // virtualPlaneDepthMeters); operators can flip to ARKitDetected
412
- // when in a controlled scene with a clearly-visible wall. Disabled
413
- // is still selectable for the older slit-scan paths that don't
414
- // need a plane.
415
- // V16 Phase 1b.fix5c (Ram's call 2026-05-10): switched default
416
- // from 'Virtual' to 'ARKitDetected'. ARKit's real plane gives
417
- // better intrinsics-to-pixel alignment than a synthesised plane
418
- // at a fixed depth, when ARKit can find a vertical plane. Falls
419
- // back to slit-scan when no plane latches.
420
- planeSource: 'ARKitDetected',
421
- virtualPlaneDepthMeters: 1.5,
422
- arkitPlaneAlignmentThreshold: 0.6,
423
- // V15.0g — Rectified is the default (Trapezoidal had the tilt-
424
- // induced bottom-wider-than-top distortion that was the field
425
- // blocker on V15.0e/f). Trapezoidal stays available for
426
- // operator A/B comparison.
427
- planeProjectionStyle: 'Rectified',
428
- // V15.0d — NCC 2D defaults match V15.0c.4's hardcoded values, now
429
- // tunable via the settings UI. EMA smoothing and pan-axis lock are
430
- // off by default so the V15.0c.4 baseline behaviour is preserved
431
- // until the operator explicitly opts in.
432
- nccSearchMargin2d: 12,
433
- // V15.0i.1 — default raised to 0.99 per Ram (only apply on near-
434
- // perfect overlap matches; reject ambiguous matches that snap to
435
- // wrong patterns on repetitive textures like shelf rails).
436
- nccConfidenceThreshold2d: 0.99,
437
- enableNcc2dEmaSmoothing: false,
438
- ncc2dEmaAlpha: 0.4,
439
- enableNcc2dPanAxisLock: false,
440
- ncc2dCrossAxisLockPx: 5,
441
- // V16 A2 (2026-05-13) — flow-based is now the default. Ram report
442
- // 2026-05-13 13:05 showed that pose-based on a small latched plane
443
- // produces "bursts" of accepts on small physical motion: a 0.64 m²
444
- // plane at 2.7 m perpDist gave 6 accepts in 1 s over 12 cm of
445
- // translation because the plane-projected polygon covers only a
446
- // sliver of the frame, hyperinflating newContent. Flow-based
447
- // measures novelty from real image content (sparse KLT), is
448
- // plane-independent, and is invariant to plane size. Operators
449
- // can still flip back to 'pose-based' or 'time-based' in the modal
450
- // for A/B testing or low-texture scenes. Same defaults shared
451
- // between pose-based and flow-based (40 % new content per
452
- // keyframe, ≤ 6 keyframes per capture).
453
- frameSelectionMode: 'flow-based',
454
- // 2026-05-15 (U4) — flow-based default novelty 0.40 → 0.20.
455
- // Accept frames with 20 % new content (was 40 %). More inclusive
456
- // selection for shelf-pan captures where panning slowly produces
457
- // gradual content reveal. Operator can still bump via Settings.
458
- keyframeOverlapThreshold: 0.20,
459
- keyframeMaxCount: 6,
460
- // V16 A2 — flow-based mode tuning. Defaults are the values that
461
- // tested cleanly on iPhone 13 Pro / 14 Pro: 150 corners give a
462
- // stable median across the frame; quality=0.01 + minDistance=10
463
- // give spatially-spread, repeatable detection. All three are
464
- // tunable in the modal under "Flow tuning".
465
- flowMaxCorners: 150,
466
- flowQualityLevel: 0.01,
467
- flowMinDistance: 10,
468
- // V16 — translation-budget force-accept (Flow strategy only).
469
- // 2026-05-16 (Issue 4a fix) — default flipped from 0 (disabled) to
470
- // 25 cm so the "Rotate the camera instead of moving it sideways"
471
- // warning fires out-of-the-box. Set to 0 in Settings to disable
472
- // both the warning AND the gate's force-accept on budget crossing.
473
- // 2026-05-17 (Issue 4-A v2) — raised 25 → 50 cm. The 25-cm budget
474
- // was too tight given IMU double-integration drift (the
475
- // accelerometer's noise floor accumulates several cm of bogus
476
- // "translation" per second even when the phone is held still).
477
- // Combined with the new `resetAnchor` at handleHoldStart (so drift
478
- // doesn't compound across captures), 50 cm gives the warning real
479
- // headroom for genuine sideways motion without false positives.
480
- flowMaxTranslationCm: 50,
481
- // V16 — novelty aggregation percentile. 0.85 picks up leading-
482
- // edge motion sooner than the pre-V16 median (0.50). Operator
483
- // can dial down toward 0.5 for more-conservative captures or up
484
- // toward 0.99 for more-aggressive.
485
- flowNoveltyPercentile: 0.85,
486
- // V16 — every-Nth-frame eval throttle. 2026-05-15 (U4): default
487
- // 1 → 5 to reduce per-frame KeyframeGate CPU cost (Shi-Tomasi +
488
- // calcOpticalFlowPyrLK is ~3-5 ms per ARFrame on Galaxy A35; at
489
- // 30 fps that's ~15 % CPU on flow alone). Evaluating every 5th
490
- // frame yields novelty samples at ~6 Hz which is still well above
491
- // the 1-2 Hz keyframe-accept cadence.
492
- // matches pre-V16 behaviour). Set higher to cut CPU on long
493
- // captures at the cost of acceptance latency.
494
- flowEvalEveryNFrames: 5,
495
- // V15.0c — sliver tweaks: leading-edge sliver from BOTTOM for typical
496
- // top-to-bottom pan + full first-frame anchor produced the best
497
- // outputs in early iteration.
498
- sliverPosition: 'Bottom',
499
- firstFrameFullFrame: true,
500
- maxRecordingMs: 8000,
501
- framesPerSecond: 3,
502
- minFrames: 6,
503
- maxFrames: 16,
504
- quality: 85,
81
+ // ─── Device-memory diagnostic (informational only) ─────────────────
82
+ //
83
+ // Read once at module load via the shared `lowMemDevice` helper. We
84
+ // surface this as a single Menlo-monospace line at the top of the
85
+ // modal body so operators can see what the SDK detected — useful for
86
+ // diagnosing "why am I OOMing on this device?" questions. The same
87
+ // helper feeds <Camera>'s initial-settings device adaptation; they
88
+ // were duplicated implementations pre-Phase-2-fix.
505
89
 
506
- // 2026-05-14 (revised) — capture source defaults to 'ar' (AR-backed
507
- // is the recommended path; non-AR is the explicit opt-out). Stitch
508
- // mode stays 'auto' — the auto-resolution heuristic between PANORAMA
509
- // and SCANS is per-capture, not per-mode, so it's safe to leave on.
510
- captureSource: 'ar',
511
- stitchMode: 'auto',
512
- debug: false,
513
- };
90
+ const _physicalMemoryBytes = getPhysicalMemoryBytes();
91
+ const _isLowMem = isLowMemDevice();
514
92
 
515
93
 
516
94
  export interface PanoramaSettingsModalProps {
@@ -527,42 +105,57 @@ export function PanoramaSettingsModal({
527
105
  onChange,
528
106
  onClose,
529
107
  }: PanoramaSettingsModalProps): React.JSX.Element {
530
- const update = (patch: Partial<PanoramaSettings>) =>
531
- onChange({ ...settings, ...patch });
532
-
533
- // V16 Phase 1b derive the 2-axis (timing × algorithm) UI state
534
- // from the underlying single `incrementalEngine` field. Storage
535
- // shape is unchanged; the modal just presents it in two segmented
536
- // controls so the user's mental model matches the system's actual
537
- // primary axis (batch vs realtime).
108
+ // ─── Sub-tree update helpers ─────────────────────────────────────
109
+ //
110
+ // Each settings sub-tree has its own update helper that
111
+ // non-destructively patches that branch and re-emits the whole
112
+ // settings object via `onChange`. Call sites stay short
113
+ // (`updateStitcher({ stitchMode: 'scans' })`) and avoid the
114
+ // nested-spread boilerplate the hierarchical shape would otherwise
115
+ // require at every callsite.
538
116
  //
539
- // Mapping:
540
- // incrementalEngine === 'batch-keyframe' → timing='batch'
541
- // incrementalEngine === 'hybrid' → timing='realtime', algo='hybrid'
542
- // incrementalEngine === 'slitscan-rotate' timing='realtime', algo='slitscan-rotate'
543
- // incrementalEngine === 'slitscan-both' → timing='realtime', algo='slitscan-both'
544
- const timing: 'batch' | 'realtime' =
545
- settings.incrementalEngine === 'batch-keyframe' ? 'batch' : 'realtime';
546
- // When in batch mode, remember 'hybrid' as the realtime algorithm
547
- // the user would land on if they flipped timing back. When already
548
- // in realtime, the engine field IS the algorithm.
549
- const realtimeAlgorithm:
550
- 'hybrid' | 'slitscan-rotate' | 'slitscan-both' =
551
- settings.incrementalEngine === 'batch-keyframe'
552
- ? 'hybrid'
553
- : settings.incrementalEngine;
554
- const setTiming = (t: 'batch' | 'realtime') => {
555
- if (t === 'batch') {
556
- update({ incrementalEngine: 'batch-keyframe' });
557
- } else {
558
- update({ incrementalEngine: realtimeAlgorithm });
559
- }
560
- };
117
+ // Why not a generic deep-merge? Type-safety: each helper takes
118
+ // exactly the `Partial<SubTree>` the section it backs can patch.
119
+ // A generic helper would accept arbitrary nested keys and break the
120
+ // type-level guarantee that the modal only mutates what its
121
+ // matching settings type defines.
561
122
 
562
- // Frame Selection only makes sense for batch and hybrid engines —
563
- // slit-scan needs dense input and the gate would starve it.
564
- const showFrameSelection =
565
- timing === 'batch' || realtimeAlgorithm === 'hybrid';
123
+ const updateBase = (patch: Partial<CaptureBaseSettings>) =>
124
+ onChange({ ...settings, ...patch });
125
+
126
+ const updateStitcher = (patch: Partial<BatchStitcherSettings>) =>
127
+ onChange({
128
+ ...settings,
129
+ stitcher: { ...settings.stitcher, ...patch },
130
+ });
131
+
132
+ const updateFrameSelection = (patch: Partial<FrameSelectionSettings>) =>
133
+ onChange({
134
+ ...settings,
135
+ frameSelection: { ...settings.frameSelection, ...patch },
136
+ });
137
+
138
+ // Flow has an extra wrinkle: `frameSelection.flow` is optional.
139
+ // We materialise it from `DEFAULT_FLOW_GATE_SETTINGS` (the
140
+ // canonical FlowGateSettings defaults — see PanoramaSettings.ts)
141
+ // when patching from "undefined" — happens if a host starts with
142
+ // a custom settings literal that omits the sub-tree.
143
+ const updateFlow = (patch: Partial<FlowGateSettings>) =>
144
+ onChange({
145
+ ...settings,
146
+ frameSelection: {
147
+ ...settings.frameSelection,
148
+ flow: {
149
+ ...(settings.frameSelection.flow ?? DEFAULT_FLOW_GATE_SETTINGS),
150
+ ...patch,
151
+ },
152
+ },
153
+ });
154
+
155
+ // Frame-selection mode controls the visibility of the nested
156
+ // Flow-tunables section. Mirrors the type-level optionality of
157
+ // `frameSelection.flow`.
158
+ const showFlowTunables = settings.frameSelection.mode === 'flow-based';
566
159
 
567
160
  return (
568
161
  <Modal
@@ -592,463 +185,187 @@ export function PanoramaSettingsModal({
592
185
  {`device: physicalMemoryBytes=${_physicalMemoryBytes} `
593
186
  + `(${(_physicalMemoryBytes / (1024 ** 3)).toFixed(2)} GB) · `
594
187
  + `isLowMem=${_isLowMem ? 'yes' : 'no'} · `
595
- + `default blender=${_isLowMem ? 'feather' : 'multiband'}`}
188
+ + `current blender=${settings.stitcher.blenderType} `
189
+ + `(low-mem fallback=${_isLowMem ? 'feather' : 'multiband'})`}
596
190
  </Text>
597
191
 
598
192
  {/* ──────────────────────────────────────────────
599
- * 2026-05-14 (revised) — CAPTURE SOURCE picker.
600
- * Two options after the Galaxy A35 vision-camera
601
- * CameraCaptureSession crash on pre-mount physical-
602
- * lens selection: 'ar' (AR-backed, default) and
603
- * 'non-ar' (vision-camera + lens-switcher chip on
604
- * the capture screen). Switching to 'non-ar'
605
- * cascades to disable plane detection, flip frame-
606
- * selection to flow-based, and turn off useARPreview
607
- * (see useEffect in AuditCaptureScreen.tsx).
193
+ * DEBUG (top-level, `debug`)
194
+ *
195
+ * Note: `captureSource` (AR vs non-AR) is intentionally
196
+ * NOT surfaced here — the camera-screen AR toggle is the
197
+ * sole source of truth. Camera.tsx computes
198
+ * `effectiveCaptureSource` from `arPreference + lens +
199
+ * AR-device-support` and overrides `settings.captureSource`
200
+ * on the bridge call, so the native engine always agrees
201
+ * with the runtime preview. Exposing a second control
202
+ * here led to silent split-state where the modal value
203
+ * disagreed with the on-screen toggle.
608
204
  * ────────────────────────────────────────────── */}
609
- <SectionHeader title="Capture source" />
610
- <SegmentedControl
611
- options={['ar', 'non-ar']}
612
- value={settings.captureSource}
613
- onChange={(v) => update({ captureSource: v as PanoramaSettings['captureSource'] })}
614
- caption="ar (default): ARKit / ARCore — plane detection, pose-aware capture, full AR stack. non-ar: vision-camera only — disables AR plane detection, flips frame-selection to flow-based, runs IMU translation gate. In non-ar mode, the on-screen lens-switcher chip lets you toggle 0.5× / 1× lens during capture (only shown when the device has both lenses)."
615
- />
616
-
617
- {/* 2026-05-14 — Stitch-mode picker. THE 2026-05-14 OOM
618
- * root cause: cv::Stitcher PANORAMA mode breaks down
619
- * on translation-heavy input. 'auto' (DEFAULT) routes
620
- * between PANORAMA and SCANS based on accumulated
621
- * translation vs rotation magnitudes at finalize time.
622
- * Lifted to the top of the modal alongside captureSource
623
- * for the same reason: it's a top-level pipeline
624
- * decision, not a per-engine tuning. */}
625
- <SectionHeader title="Stitch mode" />
626
- <SegmentedControl
627
- options={['auto', 'panorama', 'scans']}
628
- value={settings.stitchMode}
629
- onChange={(v) => update({ stitchMode: v as PanoramaSettings['stitchMode'] })}
630
- caption="auto (default): pick PANORAMA or SCANS based on translation/rotation totals at finalize. panorama: cv::Stitcher::PANORAMA — rotation-only (spherical warper, BA-ray); best for rotate-in-place captures, BAD on translation. scans: cv::Stitcher::SCANS — affine pipeline (plane warper, BA-affine); best for shelf-pan captures."
631
- />
632
-
633
- {/* ──────────────────────────────────────────────
634
- * STITCH TIMING — top-level decision. Maps to the
635
- * `incrementalEngine` storage field via setTiming().
636
- * ────────────────────────────────────────────── */}
637
- <SectionHeader title="Stitch timing" />
638
- <SegmentedControl
639
- options={['batch', 'realtime']}
640
- value={timing}
641
- onChange={(v) => setTiming(v as 'batch' | 'realtime')}
642
- caption="batch (recommended): full cv::Stitcher pipeline at shutter release. Highest quality. ~1–2 s post-release. realtime: incremental during pan; lower latency, fewer quality stages."
643
- />
644
-
645
- {/* ──────────────────────────────────────────────
646
- * FRAME SELECTION (V16) — only for batch + hybrid.
647
- * Slit-scan needs dense input; gate would starve it.
648
- * ────────────────────────────────────────────── */}
649
- {showFrameSelection && (
650
- <>
651
- <SectionHeader title="Frame selection (V16)" />
652
- <SegmentedControl
653
- options={['time-based', 'pose-based', 'flow-based']}
654
- value={settings.frameSelectionMode}
655
- onChange={(v) => update({ frameSelectionMode: v as PanoramaSettings['frameSelectionMode'] })}
656
- caption="flow-based (V16 A2, default): KeyframeGate uses sparse-Lucas-Kanade optical flow on full frame — plane-independent, invariant to plane size. pose-based: plane-polygon overlap (oversensitive on small latched planes). time-based: every ARFrame goes to the engine."
657
- />
658
- {(settings.frameSelectionMode === 'pose-based' ||
659
- settings.frameSelectionMode === 'flow-based') && (
660
- <>
661
- <SectionHeader title="Overlap threshold (new content per keyframe)" />
662
- <SegmentedControl
663
- options={['20%', '30%', '40%', '50%', '60%']}
664
- value={`${Math.round(settings.keyframeOverlapThreshold * 100)}%`}
665
- onChange={(v) => update({ keyframeOverlapThreshold: parseInt(v, 10) / 100 })}
666
- caption="Required NEW content per keyframe. 40% (default) ≈ 4–5 keyframes for a 90° pan. Same threshold semantics for both pose-based and flow-based."
667
- />
668
- <SectionHeader title="Max keyframes per capture" />
669
- <SegmentedControl
670
- options={['3', '4', '5', '6', '8', '10']}
671
- value={String(settings.keyframeMaxCount)}
672
- onChange={(v) => update({ keyframeMaxCount: parseInt(v, 10) })}
673
- caption="Hard cap. 6 (default) matches Samsung's behaviour. Once reached, host auto-finalizes."
674
- />
675
- </>
676
- )}
677
- {settings.frameSelectionMode === 'flow-based' && (
678
- <>
679
- <SectionHeader title="Flow tuning — max corners" />
680
- <SegmentedControl
681
- options={['50', '100', '150', '200', '300']}
682
- value={String(settings.flowMaxCorners)}
683
- onChange={(v) => update({ flowMaxCorners: parseInt(v, 10) })}
684
- caption="Max Shi-Tomasi corners detected per accepted keyframe. More = more robust median, slower detect. 150 = default."
685
- />
686
- <SectionHeader title="Flow tuning — quality level" />
687
- <SegmentedControl
688
- options={['0.005', '0.01', '0.02', '0.03', '0.05']}
689
- value={String(settings.flowQualityLevel)}
690
- onChange={(v) => update({ flowQualityLevel: parseFloat(v) })}
691
- caption="Shi-Tomasi corner quality threshold. Lower = more (weaker) corners; higher = fewer (stronger) corners. 0.01 = default."
692
- />
693
- <SectionHeader title="Flow tuning — min distance" />
694
- <SegmentedControl
695
- options={['5', '8', '10', '15', '20']}
696
- value={String(settings.flowMinDistance)}
697
- onChange={(v) => update({ flowMinDistance: parseInt(v, 10) })}
698
- caption="Min pixel distance between detected corners (working resolution = 720 px longest side). Higher = more spatially-spread features. 10 = default."
699
- />
700
- <SectionHeader title="Flow tuning — translation budget (cm)" />
701
- <SegmentedControl
702
- options={['0', '5', '8', '12', '20', '50']}
703
- value={String(settings.flowMaxTranslationCm)}
704
- onChange={(v) => update({ flowMaxTranslationCm: parseInt(v, 10) })}
705
- caption="Force-accept when camera has moved this many cm since last keyframe, even if novelty < overlap threshold. Bounds parallax so the stitcher can match. 0 = disabled (default). 8 = recommended starting value."
706
- />
707
- <SectionHeader title="Flow tuning — novelty percentile" />
708
- <SegmentedControl
709
- options={['0.50', '0.70', '0.85', '0.95', '0.99']}
710
- value={settings.flowNoveltyPercentile.toFixed(2)}
711
- onChange={(v) => update({ flowNoveltyPercentile: parseFloat(v) })}
712
- caption="How tracked-feature displacements are aggregated into novelty. 0.50 = pre-V16 median behaviour (conservative). 0.85 = picks up leading-edge motion sooner (default, matches user perception). 0.99 = near-max, very aggressive."
713
- />
714
- <SectionHeader title="Flow tuning — eval every N frames" />
715
- <SegmentedControl
716
- options={['1', '2', '3', '5', '10']}
717
- value={String(settings.flowEvalEveryNFrames)}
718
- onChange={(v) => update({ flowEvalEveryNFrames: parseInt(v, 10) })}
719
- caption="Throttle gate evaluation to every Nth AR frame. 1 = every frame (default, no throttle). 3-5 = noticeable CPU/battery savings on long captures, up to N-1 frames of acceptance latency."
720
- />
721
- </>
722
- )}
723
- </>
724
- )}
725
-
726
- {/* ──────────────────────────────────────────────
727
- * AR PLANE PROJECTION — used by KeyframeGate's overlap
728
- * calculation, slit-scan plane-projection, and (future)
729
- * pose-driven batch. Sub-fields reveal based on source.
730
- * ────────────────────────────────────────────── */}
731
- <SectionHeader title="AR plane projection" />
205
+ <SectionHeader title="Debug" />
732
206
  <SegmentedControl
733
- options={['Disabled', 'ARKitDetected', 'Virtual']}
734
- value={settings.planeSource}
735
- onChange={(v) => update({ planeSource: v as PanoramaSettings['planeSource'] })}
736
- caption="Disabled: no plane (gate falls back to angular delta). ARKitDetected: latch ARKit's vertical plane (best fidelity, picky). Virtual: synthesise plane perpendicular to camera at a fixed depth (always works)."
207
+ options={['off', 'on']}
208
+ value={settings.debug ? 'on' : 'off'}
209
+ onChange={(v) => updateBase({ debug: v === 'on' })}
210
+ caption="When ON, <Camera> mounts the diagnostic pills (memory, keyframes, orientation), the detailed metrics overlay, and the stitch-stats toast on every successful finalize. OFF (default) production end-user UI."
737
211
  />
738
- {settings.planeSource === 'ARKitDetected' && (
739
- <>
740
- <SectionHeader title="ARKit alignment threshold" />
741
- <SegmentedControl
742
- options={['0.3', '0.5', '0.6', '0.7', '0.85']}
743
- value={settings.arkitPlaneAlignmentThreshold.toFixed(2)}
744
- onChange={(v) => update({ arkitPlaneAlignmentThreshold: parseFloat(v) })}
745
- caption="Min dot product between candidate plane normal and camera facing. 0.6 (default) = ~53° max angle off-camera. Higher = stricter."
746
- />
747
- </>
748
- )}
749
- {settings.planeSource === 'Virtual' && (
750
- <>
751
- <SectionHeader title="Virtual plane depth" />
752
- <SegmentedControl
753
- options={['0.5m', '1.0m', '1.5m', '2.0m', '3.0m']}
754
- value={`${settings.virtualPlaneDepthMeters.toFixed(1)}m`}
755
- onChange={(v) => update({ virtualPlaneDepthMeters: parseFloat(v) })}
756
- caption="Synthetic plane depth at first frame. Set to your typical scan distance."
757
- />
758
- </>
759
- )}
760
- {settings.planeSource !== 'Disabled' && (
761
- <>
762
- <SectionHeader title="Plane projection style" />
763
- <SegmentedControl
764
- options={['Rectified', 'Trapezoidal']}
765
- value={settings.planeProjectionStyle}
766
- onChange={(v) => update({ planeProjectionStyle: v as PanoramaSettings['planeProjectionStyle'] })}
767
- caption="Rectified (default): clean rectangle paste, no tilt distortion. Trapezoidal: V15.0b legacy 3D-correct raycast — geometric purity at the cost of tilt artifacts."
768
- />
769
- </>
770
- )}
771
212
 
772
213
  {/* ──────────────────────────────────────────────
773
- * ALGORITHM what runs at stitch time. In batch mode
774
- * there's no choice (cv::Stitcher feature-matched
775
- * pipeline). In realtime, three live engines.
214
+ * FRAME SELECTION (`frameSelection` sub-tree, closed by default)
215
+ *
216
+ * Placed above Stitcher because keyframe-gate tuning is
217
+ * the more frequently touched control surface during
218
+ * capture-quality troubleshooting. Stitcher knobs are
219
+ * rarely changed at runtime.
220
+ *
221
+ * Nested Flow-tunables section reveals when mode is
222
+ * flow-based (mirrors the `frameSelection.flow` optional
223
+ * on the type).
776
224
  * ────────────────────────────────────────────── */}
777
- <SectionHeader title="Algorithm" />
778
- {timing === 'batch' ? (
779
- <View style={styles.infoBox}>
780
- <Text style={styles.infoText}>
781
- Full feature-matched pipeline:
782
- ORB → BFMatcher → RANSAC → BundleAdjusterRay →
783
- waveCorrect → Warper → GraphCutSeamFinder →
784
- ExposureCompensator → MultiBandBlender. No engine
785
- choice in batch mode.
786
- </Text>
787
- </View>
788
- ) : (
225
+ <Accordion title="Frame selection (KeyframeGate)">
226
+ <SectionHeader title="Mode" />
789
227
  <SegmentedControl
790
- options={['hybrid', 'slitscan-rotate', 'slitscan-both']}
791
- value={realtimeAlgorithm}
792
- onChange={(v) => update({ incrementalEngine: v as PanoramaSettings['incrementalEngine'] })}
793
- caption="hybrid: streaming planar projection + feature matching. slitscan-rotate: V13.0a + 1D NCC. slitscan-both: V13.0a + no accept gate + feather blend (iteration playground)."
228
+ options={['time-based', 'pose-based', 'flow-based']}
229
+ value={settings.frameSelection.mode}
230
+ onChange={(v) => updateFrameSelection({
231
+ mode: v as FrameSelectionSettings['mode'],
232
+ })}
233
+ caption="flow-based (default): sparse Shi-Tomasi + KLT optical flow. Plane-independent. pose-based: plane-overlap when a plane is latched, angular fallback otherwise — cheap but conservative. time-based: gate disabled; every frame accepted up to maxKeyframes."
794
234
  />
795
- )}
796
-
797
- {/* ──────────────────────────────────────────────
798
- * ALGORITHM TUNING — engine-specific knobs revealed
799
- * by current Algorithm choice.
800
- * ────────────────────────────────────────────── */}
801
- {timing === 'batch' && (
802
- <>
803
- {/* Capture source + stitch mode were lifted to the
804
- * TOP of the modal (above the timing picker) on
805
- * 2026-05-14 since they're pipeline-level decisions,
806
- * not batch-tuning knobs. See the top of the
807
- * ScrollView for those controls. */}
808
- <SectionHeader title="Batch tuning — Warper" />
809
- <SegmentedControl
810
- options={['plane', 'cylindrical', 'spherical']}
811
- value={settings.warperType}
812
- onChange={(v) => update({ warperType: v as PanoramaSettings['warperType'] })}
813
- caption="plane (default, recommended for retail shelves): flat rectangular output. cylindrical: rotational mid-arc, gentle curvature. spherical: wide pans (180°+) but always-curved."
814
- />
815
- <SectionHeader title="Batch tuning — Blender" />
816
- <SegmentedControl
817
- options={['multiband', 'feather']}
818
- value={settings.blenderType}
819
- onChange={(v) => update({ blenderType: v as PanoramaSettings['blenderType'] })}
820
- caption="multiband (default): Laplacian-pyramid blending; cleanest seams. feather: faster, no halo when exposure varies."
821
- />
822
- <SectionHeader title="Batch tuning — Seam finder" />
823
- <SegmentedControl
824
- options={['graphcut', 'skip']}
825
- value={settings.seamFinderType}
826
- onChange={(v) => update({ seamFinderType: v as PanoramaSettings['seamFinderType'] })}
827
- caption="graphcut (default): cv::detail::GraphCutSeamFinder; optimal seams, pairs with multiband, holds all warps in memory. skip: stream warp+feed (lower peak memory)."
828
- />
829
- <SectionHeader title="Batch tuning — Inscribed-rect crop" />
830
- <SegmentedControl
831
- options={['off', 'on']}
832
- value={settings.enableMaxInscribedRectCrop ? 'on' : 'off'}
833
- onChange={(v) => update({ enableMaxInscribedRectCrop: v === 'on' })}
834
- caption="off (default): final crop is just cv::boundingRect of non-black pixels — preserves all stitched content; may have black corners. on: additionally run MaxInscribedRectFromMask + column-projection second-pass for a clean-cornered rectangle — can shrink the output if the panorama mask is lopsided. A/B against the bbox crop on real scenes."
835
- />
836
- </>
837
- )}
838
- {timing === 'realtime' && realtimeAlgorithm === 'hybrid' && (
839
- <>
840
- <SectionHeader title="Hybrid tuning — Projection" />
841
- <SegmentedControl
842
- options={['Planar', 'Cylindrical']}
843
- value={settings.hybridProjection}
844
- onChange={(v) => update({ hybridProjection: v as PanoramaSettings['hybridProjection'] })}
845
- caption="Planar (default): cv::detail::PlaneWarper. Cylindrical: V12.x – V14.0a behaviour (legacy)."
846
- />
847
- </>
848
- )}
849
- {timing === 'realtime' && realtimeAlgorithm.startsWith('slitscan') && (
850
- <>
851
- <SectionHeader title="Slit-scan tuning — Slit width" />
852
- <SegmentedControl
853
- options={['0.01', '0.05', '0.10', '0.20', '0.30', '0.50']}
854
- value={settings.slitWidthFraction.toFixed(2)}
855
- onChange={(v) => update({ slitWidthFraction: parseFloat(v) })}
856
- caption="Fraction of pan-axis retained per sliver. 0.30 (V15 default) ≈ 324 px. Smaller = less within-slit depth disagreement."
857
- />
858
- <SectionHeader title="Slit-scan tuning — Sliver position" />
859
- <SegmentedControl
860
- options={['Center', 'Bottom', 'Top']}
861
- value={settings.sliverPosition}
862
- onChange={(v) => update({ sliverPosition: v as PanoramaSettings['sliverPosition'] })}
863
- caption="Where on the camera sensor frame the sliver is taken."
864
- />
865
- <SectionHeader title="Slit-scan tuning — Full first-frame" />
866
- <SegmentedControl
867
- options={['off', 'on']}
868
- value={settings.firstFrameFullFrame ? 'on' : 'off'}
869
- onChange={(v) => update({ firstFrameFullFrame: v === 'on' })}
870
- caption="ON: first accepted frame paints the full camera frame at the canvas anchor; subsequent frames use sliver clip."
871
- />
872
- <SectionHeader title="Slit-scan tuning — Paint mode" />
873
- <SegmentedControl
874
- options={['FirstPaintedWins', 'FeatherBlend']}
875
- value={settings.paintMode}
876
- onChange={(v) => update({ paintMode: v as PanoramaSettings['paintMode'] })}
877
- caption="FirstPaintedWins (default): protect already-painted pixels. FeatherBlend: alpha-blend new content into overlap."
878
- />
879
- </>
880
- )}
881
-
882
- {/* ──────────────────────────────────────────────
883
- * ADVANCED — 2D NCC fine-alignment (closed by default).
884
- * Used by slit-scan plane mode and any 2D NCC stage.
885
- * ────────────────────────────────────────────── */}
886
- <Accordion title="Advanced — 2D NCC fine-alignment" badge="advanced">
887
- <SectionHeader title="Enable 2D NCC" />
235
+ <SectionHeader title="Max keyframes per capture" />
888
236
  <SegmentedControl
889
- options={['off', 'on']}
890
- value={settings.enable2dNcc ? 'on' : 'off'}
891
- onChange={(v) => update({ enable2dNcc: v === 'on' })}
892
- caption="V13.0g 2D NCC fine-alignment after pose-driven projection. Refines (Δx, Δy) translation via cv::matchTemplate."
237
+ options={['3', '4', '5', '6', '8', '10']}
238
+ value={String(settings.frameSelection.maxKeyframes)}
239
+ onChange={(v) => updateFrameSelection({
240
+ maxKeyframes: parseInt(v, 10),
241
+ })}
242
+ caption="Hard cap on accepted keyframes; native clamps to [3, 10]. 6 (default) matches Samsung Pano's behaviour and is the sweet spot for cv::Stitcher BA convergence."
243
+ />
244
+ <SectionHeader title="Overlap threshold (new content per keyframe)" />
245
+ <SegmentedControl
246
+ options={['20%', '30%', '40%', '50%', '60%']}
247
+ value={`${Math.round(settings.frameSelection.overlapThreshold * 100)}%`}
248
+ onChange={(v) => updateFrameSelection({
249
+ overlapThreshold: parseInt(v, 10) / 100,
250
+ })}
251
+ caption="Required NEW-content fraction. 20% (default): generous, ~5–6 keyframes for a 90° pan. Native clamps to [10%, 80%]."
893
252
  />
894
- {settings.enable2dNcc && (
895
- <>
896
- <SectionHeader title="Confidence threshold" />
253
+
254
+ {showFlowTunables && (
255
+ <View style={styles.nested}>
256
+ <Text style={styles.nestedLabel}>Flow tuning</Text>
257
+ <SectionHeader title="Max corners (Shi-Tomasi)" />
258
+ <SegmentedControl
259
+ options={['50', '100', '150', '200', '300']}
260
+ value={String(settings.frameSelection.flow?.maxCorners
261
+ ?? DEFAULT_FLOW_GATE_SETTINGS.maxCorners)}
262
+ onChange={(v) => updateFlow({ maxCorners: parseInt(v, 10) })}
263
+ caption="More corners = more robust median displacement, slower detect. 150 (default) ~ 15–25 ms / frame on Galaxy A35. Native clamps to [50, 300]."
264
+ />
265
+ <SectionHeader title="Quality level (Shi-Tomasi)" />
897
266
  <SegmentedControl
898
- options={['0.50', '0.65', '0.75', '0.85', '0.95', '0.99']}
899
- value={settings.nccConfidenceThreshold2d.toFixed(2)}
900
- onChange={(v) => update({ nccConfidenceThreshold2d: parseFloat(v) })}
901
- caption="Reject NCC corrections below this confidence. 0.99 = only apply on near-perfect overlap."
267
+ options={['0.005', '0.01', '0.02', '0.03', '0.05']}
268
+ value={String(settings.frameSelection.flow?.qualityLevel
269
+ ?? DEFAULT_FLOW_GATE_SETTINGS.qualityLevel)}
270
+ onChange={(v) => updateFlow({ qualityLevel: parseFloat(v) })}
271
+ caption="Lower lets weaker corners in; higher demands stronger corners. 0.01 (default). Clamped to [0.005, 0.05]."
902
272
  />
903
- <SectionHeader title="Search half-window (px)" />
273
+ <SectionHeader title="Min distance (working-resolution px)" />
904
274
  <SegmentedControl
905
- options={['6', '10', '12', '20', '30']}
906
- value={String(settings.nccSearchMargin2d)}
907
- onChange={(v) => update({ nccSearchMargin2d: parseInt(v, 10) })}
908
- caption="Pixels: 2D NCC searches ±this around the pose-predicted match."
275
+ options={['5', '8', '10', '15', '20']}
276
+ value={String(settings.frameSelection.flow?.minDistance
277
+ ?? DEFAULT_FLOW_GATE_SETTINGS.minDistance)}
278
+ onChange={(v) => updateFlow({ minDistance: parseInt(v, 10) })}
279
+ caption="Min pixel distance between detected corners (working res = 720 px longest side). 10 (default). Clamped to [1, 50]."
909
280
  />
910
- <SectionHeader title="EMA smoothing" />
281
+ <SectionHeader title="Translation budget (cm)" />
911
282
  <SegmentedControl
912
- options={['off', 'on']}
913
- value={settings.enableNcc2dEmaSmoothing ? 'on' : 'off'}
914
- onChange={(v) => update({ enableNcc2dEmaSmoothing: v === 'on' })}
915
- caption="Damp single-frame snaps to spurious peaks via EMA."
283
+ options={['0', '5', '8', '12', '20', '50']}
284
+ value={String(settings.frameSelection.flow?.maxTranslationCm
285
+ ?? DEFAULT_FLOW_GATE_SETTINGS.maxTranslationCm)}
286
+ onChange={(v) => updateFlow({
287
+ maxTranslationCm: parseInt(v, 10),
288
+ })}
289
+ caption="Force-accept the next frame once the operator has translated this many cm since the last keyframe, even when novelty < threshold. Bounds parallax so cv::Stitcher's matcher can handle the input. 50 (default). 0 disables. Clamped to [0, 100]."
916
290
  />
917
- {settings.enableNcc2dEmaSmoothing && (
918
- <>
919
- <SectionHeader title="EMA alpha (current-frame weight)" />
920
- <SegmentedControl
921
- options={['0.20', '0.30', '0.40', '0.60', '0.80']}
922
- value={settings.ncc2dEmaAlpha.toFixed(2)}
923
- onChange={(v) => update({ ncc2dEmaAlpha: parseFloat(v) })}
924
- />
925
- </>
926
- )}
927
- <SectionHeader title="Pan-axis lock" />
291
+ <SectionHeader title="Novelty percentile" />
928
292
  <SegmentedControl
929
- options={['off', 'on']}
930
- value={settings.enableNcc2dPanAxisLock ? 'on' : 'off'}
931
- onChange={(v) => update({ enableNcc2dPanAxisLock: v === 'on' })}
932
- caption="Clamp cross-axis correction tighter than pan-axis (pose + 1D NCC handle cross-axis already)."
293
+ options={['0.50', '0.70', '0.85', '0.95', '0.99']}
294
+ value={(settings.frameSelection.flow?.noveltyPercentile
295
+ ?? DEFAULT_FLOW_GATE_SETTINGS.noveltyPercentile).toFixed(2)}
296
+ onChange={(v) => updateFlow({
297
+ noveltyPercentile: parseFloat(v),
298
+ })}
299
+ caption="How tracked-feature displacements aggregate into a per-axis novelty estimate. 0.85 (default): picks up leading-edge motion sooner — matches user perception. 0.50: pre-V16 median (conservative). 0.99: very aggressive. Clamped to [0.50, 0.99]."
933
300
  />
934
- {settings.enableNcc2dPanAxisLock && (
935
- <>
936
- <SectionHeader title="Cross-axis clamp (px)" />
937
- <SegmentedControl
938
- options={['2', '5', '10', '15']}
939
- value={String(settings.ncc2dCrossAxisLockPx)}
940
- onChange={(v) => update({ ncc2dCrossAxisLockPx: parseInt(v, 10) })}
941
- />
942
- </>
943
- )}
944
- </>
301
+ <SectionHeader title="Eval every N frames" />
302
+ <SegmentedControl
303
+ options={['1', '2', '3', '5', '10']}
304
+ value={String(settings.frameSelection.flow?.evalEveryNFrames
305
+ ?? DEFAULT_FLOW_GATE_SETTINGS.evalEveryNFrames)}
306
+ onChange={(v) => updateFlow({
307
+ evalEveryNFrames: parseInt(v, 10),
308
+ })}
309
+ caption="Throttle gate evaluation to every Nth frame for CPU savings. 5 (default) gives ~6 Hz novelty samples at 30 Hz ARCore. Doesn't change WHICH frames are accepted; only the sample rate. Clamped to [1, 10]."
310
+ />
311
+ </View>
945
312
  )}
946
313
  </Accordion>
947
314
 
948
315
  {/* ──────────────────────────────────────────────
949
- * ADVANCED Slit-scan experimental. Only relevant
950
- * when slitscan-both is the active engine.
951
- * ────────────────────────────────────────────── */}
952
- {timing === 'realtime' && realtimeAlgorithm === 'slitscan-both' && (
953
- <Accordion title="Advanced — Slit-scan experimental" badge="experimental">
954
- <SectionHeader title="Triangulation parallax" />
955
- <SegmentedControl
956
- options={['off', 'on']}
957
- value={settings.enableTriangulation ? 'on' : 'off'}
958
- onChange={(v) => update({ enableTriangulation: v === 'on' })}
959
- caption="V13.0e ORB triangulation + median-Z parallax correction. Adds ~10ms/accept."
960
- />
961
- <SectionHeader title="RANSAC homography" />
962
- <SegmentedControl
963
- options={['off', 'on']}
964
- value={settings.enableRansacHomography ? 'on' : 'off'}
965
- onChange={(v) => update({ enableRansacHomography: v === 'on' })}
966
- caption="V14.0a RANSAC homography per slit + cv::warpPerspective. Known limitation: can absorb pan as scale, leaving gaps."
967
- />
968
- <SectionHeader title="Accept gate (px)" />
969
- <SegmentedControl
970
- options={['0', '50']}
971
- value={String(settings.acceptGate)}
972
- onChange={(v) => update({ acceptGate: parseInt(v, 10) as PanoramaSettings['acceptGate'] })}
973
- caption="0 = accept on every frame (Apple-dense). 50 = V13.0g throttle."
974
- />
975
- </Accordion>
976
- )}
977
-
978
- {/* ──────────────────────────────────────────────
979
- * OUTPUT — always visible.
316
+ * STITCHER (`stitcher` sub-tree, closed by default)
980
317
  * ────────────────────────────────────────────── */}
981
- <SectionHeader title="Recording cap" />
982
- <SegmentedControl
983
- options={['4 s', '6 s', '8 s', '10 s']}
984
- value={`${Math.round(settings.maxRecordingMs / 1000)} s`}
985
- onChange={(v) => update({ maxRecordingMs: parseInt(v, 10) * 1000 })}
986
- caption="Auto-stops the hold-recording at this duration."
987
- />
988
- <SectionHeader title="JPEG quality" />
989
- <SegmentedControl
990
- options={['70', '85', '92']}
991
- value={String(settings.quality)}
992
- onChange={(v) => update({ quality: parseInt(v, 10) })}
993
- caption="Higher = bigger files, sharper detail. 85 is the recommended default."
994
- />
995
-
996
- {/* ──────────────────────────────────────────────
997
- * DEBUG — surfaces stitch telemetry to the operator on
998
- * every successful finalize. See PanoramaSettings.debug.
999
- * ────────────────────────────────────────────── */}
1000
- <SectionHeader title="Debug" />
1001
- <SegmentedControl
1002
- options={['off', 'on']}
1003
- value={settings.debug ? 'on' : 'off'}
1004
- onChange={(v) => update({ debug: v === 'on' })}
1005
- caption="When ON, every successful stitch shows a popup with the C+D progressive-confidence retry telemetry (frames included, final threshold, retry attempts). Off by default."
1006
- />
1007
-
1008
- {/* ──────────────────────────────────────────────
1009
- * DIAGNOSTICS / FALLBACKS — closed by default. AR is
1010
- * the active path for 99% of use; the vision-camera
1011
- * fallback path lives here for emergencies.
1012
- * ────────────────────────────────────────────── */}
1013
- <Accordion title="Diagnostics / fallbacks" badge="rarely needed">
1014
- <View style={styles.infoBox}>
1015
- <Text style={styles.infoText}>
1016
- AR-backed capture is the recommended path. Toggle off
1017
- ONLY if ARKit fails on a specific device (very rare on
1018
- modern iPhones). Doing so falls back to vision-camera
1019
- video recording + post-stitch via cv::Stitcher.
1020
- </Text>
1021
- </View>
1022
- <SectionHeader title="AR-backed capture" />
318
+ <Accordion title="Stitcher (cv::Stitcher knobs)">
319
+ <SectionHeader title="Stitch mode" />
1023
320
  <SegmentedControl
1024
- options={['on', 'off']}
1025
- value={settings.useARPreview ? 'on' : 'off'}
1026
- onChange={(v) => update({ useARPreview: v === 'on' })}
1027
- caption="Default ON. OFF only when ARKit is unavailable or for A/B testing."
321
+ options={['auto', 'panorama', 'scans']}
322
+ value={settings.stitcher.stitchMode}
323
+ onChange={(v) => updateStitcher({
324
+ stitchMode: v as BatchStitcherSettings['stitchMode'],
325
+ })}
326
+ caption="auto (default): pick PANORAMA or SCANS based on translation/rotation totals at finalize. panorama: rotation-only (spherical warper, BA-Ray) — best for rotate-in-place captures; BAD on translation. scans: affine pipeline (plane warper, BA-affine) — best for shelf-pan captures; never diverges on rotation either. Both modes auto-retry with the opposite if camera params come out degenerate."
327
+ />
328
+ <SectionHeader title="Warper" />
329
+ <SegmentedControl
330
+ options={['plane', 'cylindrical', 'spherical']}
331
+ value={settings.stitcher.warperType}
332
+ onChange={(v) => updateStitcher({
333
+ warperType: v as BatchStitcherSettings['warperType'],
334
+ })}
335
+ caption="plane (default): flat rectangular output, best for retail shelves. cylindrical: rotational mid-arc. spherical: wide pans (180°+), always curved. Only consulted in panorama mode; scans hardwires PlaneWarper."
336
+ />
337
+ <SectionHeader title="Blender" />
338
+ <SegmentedControl
339
+ options={['multiband', 'feather']}
340
+ value={settings.stitcher.blenderType}
341
+ onChange={(v) => updateStitcher({
342
+ blenderType: v as BatchStitcherSettings['blenderType'],
343
+ })}
344
+ caption="multiband (default): Laplacian-pyramid blending; cleanest seams, holds all warped frames in memory. feather: streams warp+feed (lower peak memory, no halo with varied exposure). <Camera> auto-picks feather on low-memory devices."
345
+ />
346
+ <SectionHeader title="Seam finder" />
347
+ <SegmentedControl
348
+ options={['graphcut', 'skip']}
349
+ value={settings.stitcher.seamFinderType}
350
+ onChange={(v) => updateStitcher({
351
+ seamFinderType: v as BatchStitcherSettings['seamFinderType'],
352
+ })}
353
+ caption="graphcut (default): cv::detail::GraphCutSeamFinder for optimal seams; pairs with multiband. skip: stream warp+feed (lowest-memory configuration; pair with feather)."
354
+ />
355
+ <SectionHeader title="Inscribed-rect crop" />
356
+ <SegmentedControl
357
+ options={['off', 'on']}
358
+ value={settings.stitcher.enableMaxInscribedRectCrop ? 'on' : 'off'}
359
+ onChange={(v) => updateStitcher({
360
+ enableMaxInscribedRectCrop: v === 'on',
361
+ })}
362
+ caption="off (default): crop to cv::boundingRect of non-black pixels — preserves all stitched content; may leave black corners. on: run MaxInscribedRectFromMask + column-projection second-pass for a clean rectangle (can shrink output if mask is lopsided)."
1028
363
  />
1029
- {!settings.useARPreview && (
1030
- <>
1031
- <SectionHeader title="Frame extraction — Frames per second" />
1032
- <SegmentedControl
1033
- options={['2', '3', '4']}
1034
- value={String(settings.framesPerSecond)}
1035
- onChange={(v) => update({ framesPerSecond: parseInt(v, 10) })}
1036
- caption="Frames/sec extracted from the recorded video. Lower = faster but riskier overlap."
1037
- />
1038
- <SectionHeader title="Frame extraction — Frame count clamp" />
1039
- <SegmentedControl
1040
- options={['4-12', '6-16', '8-20']}
1041
- value={`${settings.minFrames}-${settings.maxFrames}`}
1042
- onChange={(v) => {
1043
- const [min, max] = v.split('-').map((n) => parseInt(n, 10));
1044
- update({ minFrames: min, maxFrames: max });
1045
- }}
1046
- caption="Floor/ceiling for extracted frames."
1047
- />
1048
- </>
1049
- )}
1050
364
  </Accordion>
1051
365
 
366
+ {/* ──────────────────────────────────────────────
367
+ * RESET TO DEFAULTS
368
+ * ────────────────────────────────────────────── */}
1052
369
  <Pressable
1053
370
  onPress={() => onChange(DEFAULT_PANORAMA_SETTINGS)}
1054
371
  style={styles.resetBtn}
@@ -1065,21 +382,20 @@ export function PanoramaSettingsModal({
1065
382
  }
1066
383
 
1067
384
 
385
+ // ════════════════════════════════════════════════════════════════════
386
+ // Helpers (kept verbatim from v0.3 — presentational primitives the
387
+ // modal composes; nothing in here depends on the settings shape).
388
+ // ════════════════════════════════════════════════════════════════════
389
+
1068
390
  function SectionHeader({ title }: { title: string }) {
1069
391
  return <Text style={styles.sectionHeader}>{title}</Text>;
1070
392
  }
1071
393
 
1072
394
 
1073
395
  /**
1074
- * Collapsible section. Used for closed-by-default groupings
1075
- * ("Advanced", "Diagnostics / fallbacks") so the modal's primary
1076
- * surface stays focused on the controls operators actually touch
1077
- * day-to-day.
1078
- *
1079
- * State is local — each Accordion instance manages its own open
1080
- * flag. The modal opens fresh-collapsed every mount which is what
1081
- * we want for now; persisting open state across mounts (e.g. via
1082
- * AsyncStorage) is a future enhancement.
396
+ * Collapsible section. Each instance owns its open/closed state;
397
+ * the modal opens fresh-collapsed on every mount, which is what we
398
+ * want (no AsyncStorage roundtrip on every settings tweak).
1083
399
  */
1084
400
  function Accordion({
1085
401
  title,
@@ -1113,9 +429,10 @@ function Accordion({
1113
429
 
1114
430
 
1115
431
  /**
1116
- * Small grey-text badge. Marks sections / fields as "advanced",
1117
- * "experimental", "legacy", or similar quick visual signal that
1118
- * the operator can usually ignore them.
432
+ * Small grey-text badge marks sections as "advanced",
433
+ * "experimental", or similar. No semantic effect; purely a quick
434
+ * visual signal. Kept for future Layer-2 settings modals that may
435
+ * want to flag experimental sub-trees.
1119
436
  */
1120
437
  function Tag({ label }: { label: string }): React.JSX.Element {
1121
438
  return (
@@ -1227,18 +544,21 @@ const styles = StyleSheet.create({
1227
544
  marginTop: 18,
1228
545
  marginBottom: 8,
1229
546
  },
1230
- row: {
1231
- marginTop: 4,
547
+ // Nested-sub-section label inside an accordion body — used for the
548
+ // Flow-tunables sub-tree under Frame selection.
549
+ nested: {
550
+ marginTop: 12,
551
+ paddingTop: 12,
552
+ borderTopWidth: StyleSheet.hairlineWidth,
553
+ borderTopColor: 'rgba(255,255,255,0.08)',
1232
554
  },
1233
- label: {
1234
- color: '#ffffff',
1235
- opacity: 0.85,
1236
- fontSize: 13,
555
+ nestedLabel: {
556
+ color: 'rgba(255,255,255,0.55)',
557
+ fontSize: 11,
1237
558
  fontWeight: '600',
1238
559
  textTransform: 'uppercase',
1239
- letterSpacing: 0.5,
1240
- marginTop: 18,
1241
- marginBottom: 8,
560
+ letterSpacing: 0.8,
561
+ marginBottom: 4,
1242
562
  },
1243
563
  segmentedRow: {
1244
564
  flexDirection: 'row',
@@ -1298,7 +618,6 @@ const styles = StyleSheet.create({
1298
618
  fontSize: 14,
1299
619
  fontWeight: '500',
1300
620
  },
1301
- // V16 Phase 1b — Accordion + Tag + InfoBox
1302
621
  accordion: {
1303
622
  marginTop: 18,
1304
623
  backgroundColor: 'rgba(255,255,255,0.04)',
@@ -1343,15 +662,4 @@ const styles = StyleSheet.create({
1343
662
  textTransform: 'uppercase',
1344
663
  letterSpacing: 0.5,
1345
664
  },
1346
- infoBox: {
1347
- backgroundColor: 'rgba(255,255,255,0.06)',
1348
- borderRadius: 8,
1349
- padding: 12,
1350
- marginTop: 4,
1351
- },
1352
- infoText: {
1353
- color: 'rgba(255,255,255,0.75)',
1354
- fontSize: 12,
1355
- lineHeight: 17,
1356
- },
1357
665
  });