編譯前將照片縮至長邊 1280px,修正 iPhone 掃描無反應
根本原因: 管理頁把原始解析度照片(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 <noreply@anthropic.com>
This commit is contained in:
+16
-1
@@ -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) + '%(勿關閉頁面)…';
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user