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) <noreply@anthropic.com>
This commit is contained in:
parent
e94a814335
commit
fe61ba3cf2
@ -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
|
/** Estimate the image-pixels-per-mm implied by a single datum. Picks the
|
||||||
* best datum by type priority (rect > line > ellipse) and then confidence.
|
* best datum by type priority (rect > line > ellipse) and then confidence.
|
||||||
@ -123,16 +125,16 @@ function computeAutoScale(): number {
|
|||||||
const ref = pickScaleRef()
|
const ref = pickScaleRef()
|
||||||
if (!img || !ref || ref.srcPxPerMm <= 0) return DEFAULT_SCALE_PX_PER_MM
|
if (!img || !ref || ref.srcPxPerMm <= 0) return DEFAULT_SCALE_PX_PER_MM
|
||||||
|
|
||||||
let autoScale = ref.srcPxPerMm
|
// The full warped output is roughly the source image scaled by
|
||||||
|
// (outputPxPerMm / srcPxPerMm). Pick outputPxPerMm so the larger of
|
||||||
// Clamp so the full output doesn't exceed MAX_AUTO_SCALE_DIM
|
// the two output dimensions lands at AUTO_SCALE_TARGET_DIM; floor so
|
||||||
const estMax = Math.max(img.naturalWidth, img.naturalHeight)
|
// the shown value round-trips through the integer-only input; clamp
|
||||||
if (estMax > MAX_AUTO_SCALE_DIM) {
|
// at 1 to avoid useless 0 px/mm.
|
||||||
autoScale *= MAX_AUTO_SCALE_DIM / estMax
|
const imgMaxDim = Math.max(img.naturalWidth, img.naturalHeight)
|
||||||
}
|
if (imgMaxDim <= 0) return DEFAULT_SCALE_PX_PER_MM
|
||||||
|
const target =
|
||||||
// The scale input is integer-only; floor so the shown value round-trips.
|
(AUTO_SCALE_TARGET_DIM * ref.srcPxPerMm) / imgMaxDim
|
||||||
return Math.max(1, Math.floor(autoScale))
|
return Math.max(1, Math.floor(target))
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user