diff --git a/web/work_plane.js b/web/work_plane.js index 00f33f4..a224ccc 100644 --- a/web/work_plane.js +++ b/web/work_plane.js @@ -61,12 +61,17 @@ function startRgbLoop() { } function syncOverlaySize() { - overlay.width = img.naturalWidth || 640; - overlay.height = img.naturalHeight || 480; + // Setting width/height on a canvas wipes its content. Only re-set when + // the image resolution actually changes (rare) so the ROI overlay survives + // each RGB live-refresh tick. + const w = img.naturalWidth || 640; + const h = img.naturalHeight || 480; + if (overlay.width !== w) overlay.width = w; + if (overlay.height !== h) overlay.height = h; overlay.style.width = img.clientWidth + 'px'; overlay.style.height = img.clientHeight + 'px'; } - img.addEventListener('load', syncOverlaySize); + img.addEventListener('load', () => { syncOverlaySize(); drawOverlay(); }); // Two-click ROI: 1st click = corner A, 2nd click = corner B (rectangle // defined). 3rd click starts a new selection.