[segment-anything] add multi point logic for demo site (#1002)

* [segment-anything] add multi point logic for demo site

* [segment-anything] remove libs and update functions
This commit is contained in:
lichin-lin
2023-10-01 18:25:22 +01:00
committed by GitHub
parent 096dee7073
commit 41143db1af
3 changed files with 29 additions and 14 deletions

View File

@ -33,6 +33,7 @@
url: "sam_vit_b_01ec64.safetensors",
},
};
let pointArr = []
const samWorker = new Worker("./samWorker.js", { type: "module" });
async function segmentPoints(
@ -145,6 +146,7 @@
//add event listener to clear button
clearBtn.addEventListener("click", () => {
cleanImageCanvas();
pointArr = []
});
//add click event to canvas
canvas.addEventListener("click", async (event) => {
@ -155,7 +157,8 @@
const x = (event.clientX - targetBox.left) / targetBox.width;
const y = (event.clientY - targetBox.top) / targetBox.height;
isSegmenting = true;
const { maskURL } = await getSegmentationMask({ x, y });
pointArr = [...pointArr, [ x, y , true ]]
const { maskURL } = await getSegmentationMask(pointArr);
isSegmenting = false;
drawMask(maskURL);
});