summaryrefslogtreecommitdiff
path: root/candle-wasm-examples/segment-anything/lib-example.html
diff options
context:
space:
mode:
authorlichin-lin <vic20087cjimlin@gmail.com>2023-10-01 18:25:22 +0100
committerGitHub <noreply@github.com>2023-10-01 18:25:22 +0100
commit41143db1afd47b1037b29d44d9a8eebe44e5b508 (patch)
treec1d3e0195f2ffdc1f427d3a896c01981ab59bc2b /candle-wasm-examples/segment-anything/lib-example.html
parent096dee7073e960f4b845a430b889a9fb2f2f0c78 (diff)
downloadcandle-41143db1afd47b1037b29d44d9a8eebe44e5b508.tar.gz
candle-41143db1afd47b1037b29d44d9a8eebe44e5b508.tar.bz2
candle-41143db1afd47b1037b29d44d9a8eebe44e5b508.zip
[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
Diffstat (limited to 'candle-wasm-examples/segment-anything/lib-example.html')
-rw-r--r--candle-wasm-examples/segment-anything/lib-example.html5
1 files changed, 4 insertions, 1 deletions
diff --git a/candle-wasm-examples/segment-anything/lib-example.html b/candle-wasm-examples/segment-anything/lib-example.html
index 5060f073..6684f1a1 100644
--- a/candle-wasm-examples/segment-anything/lib-example.html
+++ b/candle-wasm-examples/segment-anything/lib-example.html
@@ -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);
});