From fe61ba3cf27d8e3a9b5182e5e3cda0f536d0b45b Mon Sep 17 00:00:00 2001 From: Samuel Prevost Date: Sat, 25 Apr 2026 09:57:52 +0200 Subject: [PATCH] fix(result): default auto-scale targets a 2000px output Previously the auto-scale was just the source-image px/mm of the chosen reference datum, which produced enormous outputs for high-res photos. Pick the output px/mm so the longer side of the warped image is roughly 2000 px; floor to int (the input is integer-only); clamp at 1. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/components/ResultViewer.vue | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/components/ResultViewer.vue b/src/components/ResultViewer.vue index b3125d9..b9ca991 100644 --- a/src/components/ResultViewer.vue +++ b/src/components/ResultViewer.vue @@ -57,7 +57,9 @@ watch(scaleInput, (v) => { } }) -const MAX_AUTO_SCALE_DIM = 8192 +/** Max dimension (px) of the auto-suggested output. Picked so default + * exports stay under a few MB and OpenCV's WASM doesn't choke. */ +const AUTO_SCALE_TARGET_DIM = 2000 /** Estimate the image-pixels-per-mm implied by a single datum. Picks the * best datum by type priority (rect > line > ellipse) and then confidence. @@ -123,16 +125,16 @@ function computeAutoScale(): number { const ref = pickScaleRef() if (!img || !ref || ref.srcPxPerMm <= 0) return DEFAULT_SCALE_PX_PER_MM - let autoScale = ref.srcPxPerMm - - // Clamp so the full output doesn't exceed MAX_AUTO_SCALE_DIM - const estMax = Math.max(img.naturalWidth, img.naturalHeight) - if (estMax > MAX_AUTO_SCALE_DIM) { - autoScale *= MAX_AUTO_SCALE_DIM / estMax - } - - // The scale input is integer-only; floor so the shown value round-trips. - return Math.max(1, Math.floor(autoScale)) + // The full warped output is roughly the source image scaled by + // (outputPxPerMm / srcPxPerMm). Pick outputPxPerMm so the larger of + // the two output dimensions lands at AUTO_SCALE_TARGET_DIM; floor so + // the shown value round-trips through the integer-only input; clamp + // at 1 to avoid useless 0 px/mm. + const imgMaxDim = Math.max(img.naturalWidth, img.naturalHeight) + if (imgMaxDim <= 0) return DEFAULT_SCALE_PX_PER_MM + const target = + (AUTO_SCALE_TARGET_DIM * ref.srcPxPerMm) / imgMaxDim + return Math.max(1, Math.floor(target)) } onMounted(() => {