新增「框選辨識主體」功能,降低相似照片互相認錯(掃描頁 v9)
根本原因: MindAR 以整張照片的特徵點做比對,同場地、同構圖的照片 (例如活動現場連拍)大部分特徵點落在共同背景(場地線條、 天花板、浮水印),會穩定地互相認錯、播出別張的影片。 調高 warmupTolerance 實測無效:錯誤目標是持續穩定匹配, 嚴格化只是更慢地確認錯的答案。 影響: 背景相似的多組照片無法在同一個特徵檔中正確區分。 修法: 1. 管理頁每組配對新增「框主體」:在照片上拖曳框選最有辨識度 的區域(相對座標存於 pairs.json,照片檔不動),編譯時只用 框內影像產生特徵。框的長寬下限 15%,實測框太小(僅臉部 特寫)會特徵點不足而完全偵測不到。 2. server 新增 PUT /api/pairs/:id/crop 儲存裁切框;更動後 自動標記「有變更尚未編譯」。 3. 掃描頁依 mapping 中的 aspect 與 crop 將影片平面放大平移, 辨識目標雖只是照片的一塊,影片仍精確覆蓋整張照片 (已用假相機截圖驗證幾何)。無裁切的舊資料行為不變。 已知限制:兩張照片若互相拍到彼此的主體(同兩人、同場地的 連拍),框選也無法完全區分——框內容本來就存在於另一張裡。 這種情況仍建議更換其中一張照片。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -137,6 +137,28 @@ shared.post(
|
||||
}
|
||||
);
|
||||
|
||||
// 裁切框(相對座標 0~1,null 表示用整張照片)。只影響編譯輸入,照片檔不動
|
||||
function isValidCrop(c) {
|
||||
if (c === null) return true;
|
||||
if (!c || typeof c !== 'object') return false;
|
||||
const nums = [c.x, c.y, c.w, c.h];
|
||||
if (!nums.every((n) => typeof n === 'number' && Number.isFinite(n))) return false;
|
||||
return c.x >= 0 && c.y >= 0 && c.w > 0 && c.h > 0 && c.x + c.w <= 1.0001 && c.y + c.h <= 1.0001;
|
||||
}
|
||||
|
||||
shared.put('/api/pairs/:id/crop', express.json(), (req, res) => {
|
||||
const pair = db.pairs.find((p) => p.id === req.params.id);
|
||||
if (!pair) return res.status(404).json({ error: '找不到這組配對' });
|
||||
const crop = req.body ? req.body.crop : undefined;
|
||||
if (crop === undefined || !isValidCrop(crop)) {
|
||||
return res.status(400).json({ error: 'crop 格式錯誤(需為 null 或 {x,y,w,h} 相對座標)' });
|
||||
}
|
||||
if (crop === null) delete pair.crop;
|
||||
else pair.crop = { x: +crop.x.toFixed(4), y: +crop.y.toFixed(4), w: +crop.w.toFixed(4), h: +crop.h.toFixed(4) };
|
||||
persistDb();
|
||||
res.json({ ok: true, pair });
|
||||
});
|
||||
|
||||
shared.delete('/api/pairs/:id', (req, res) => {
|
||||
const idx = db.pairs.findIndex((p) => p.id === req.params.id);
|
||||
if (idx === -1) return res.status(404).json({ error: '找不到這組配對' });
|
||||
|
||||
Reference in New Issue
Block a user