From c894b98e489c793c1713b2e7314db81719367b39 Mon Sep 17 00:00:00 2001 From: JianMiau Date: Tue, 28 Jul 2026 10:55:45 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B7=A8=E8=AD=AF=E5=89=8D=E5=B0=87=E7=85=A7?= =?UTF-8?q?=E7=89=87=E7=B8=AE=E8=87=B3=E9=95=B7=E9=82=8A=201280px=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20iPhone=20=E6=8E=83=E6=8F=8F=E7=84=A1?= =?UTF-8?q?=E5=8F=8D=E6=87=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根本原因: 管理頁把原始解析度照片(2244x4131)直接餵給 MindAR 編譯器,特徵檔隨圖片尺寸與張數暴漲。2 張時 iOS Safari 勉強可用,新增至 4 張重新編譯後,掃描頁的 WebGL 資源超出 iOS 上限,辨識引擎無聲失效——相機畫面正常但掃任何照片都沒反應;桌面 Chrome 資源上限較高所以不受影響。 影響: NAS 部署(4 組配對)後 iPhone 完全無法辨識任何照片,服務等同不可用。 修法: 編譯前先在瀏覽器端把照片縮到長邊 1280px(canvas 縮圖後餵給編譯器),特徵檔由 4.05MB 降為 2.76MB。已用 Playwright 假相機對 NAS 實測,4 張照片皆可在 2 秒內辨識並播放對應影片;配對 aspect 仍以原圖計算,顯示比例不變。 Co-Authored-By: Claude Fable 5 --- public/admin.html | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/public/admin.html b/public/admin.html index 1ff47a0..17203ef 100644 --- a/public/admin.html +++ b/public/admin.html @@ -211,9 +211,24 @@ document.getElementById('compileBtn').addEventListener('click', async () => { pairs.map((p) => loadImage('/data/photos/' + encodeURIComponent(p.photo))) ); + // 大圖先縮到長邊 1280px 再編譯:特徵品質足夠, + // 且 .mind 檔與掃描端(尤其 iOS Safari)的 WebGL 記憶體用量大幅下降。 + // 曾發生 4 張 2244x4131 原圖直接編譯後,iPhone 掃任何照片都沒反應 + // (桌面 Chrome 正常,iOS WebGL 資源上限較低,辨識引擎無聲掛掉) + const MAX_EDGE = 1280; + const compileInputs = images.map((img) => { + const scale = Math.min(1, MAX_EDGE / Math.max(img.naturalWidth, img.naturalHeight)); + if (scale === 1) return img; + const c = document.createElement('canvas'); + c.width = Math.round(img.naturalWidth * scale); + c.height = Math.round(img.naturalHeight * scale); + c.getContext('2d').drawImage(img, 0, 0, c.width, c.height); + return c; + }); + status.textContent = '編譯特徵中(勿關閉頁面)…'; const compiler = new window.MINDAR.IMAGE.Compiler(); - await compiler.compileImageTargets(images, (progress) => { + await compiler.compileImageTargets(compileInputs, (progress) => { bar.value = progress; status.textContent = '編譯特徵中 ' + progress.toFixed(0) + '%(勿關閉頁面)…'; });