fix: segment not updated
This commit is contained in:
+14
-8
@@ -71,7 +71,7 @@ function handleImageSize(image) {
|
||||
return { height: h, width: w, samScale };
|
||||
}
|
||||
|
||||
function getClicks() {
|
||||
export function getClicks() {
|
||||
return imagePrompts.val.map((point) => ({
|
||||
x: point.x,
|
||||
y: point.y,
|
||||
@@ -79,13 +79,19 @@ function getClicks() {
|
||||
}));
|
||||
}
|
||||
|
||||
function drawSegment(clicks) {
|
||||
runONNX(clicks, embeddings.val).then((mask) => {
|
||||
const canvas = document.getElementById("mask-canvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
export function drawSegment(clicks) {
|
||||
const canvas = document.getElementById("mask-canvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (clicks.length === 0) {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.drawImage(mask, 0, 0);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (embeddings.val) {
|
||||
runONNX(clicks, embeddings.val).then((mask) => {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.drawImage(mask, 0, 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
initModel();
|
||||
@@ -96,7 +102,7 @@ export function ImageEditor() {
|
||||
if (showImageEditor.val && e.code === "Tab") {
|
||||
e.preventDefault();
|
||||
realTimeSegment = !realTimeSegment;
|
||||
if (!realTimeSegment && embeddings.val) {
|
||||
if (!realTimeSegment) {
|
||||
drawSegment(getClicks());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
import { updateImagePrompts } from "./ImageEditor.js";
|
||||
import { drawSegment, getClicks, updateImagePrompts } from "./ImageEditor.js";
|
||||
import {
|
||||
imagePrompts,
|
||||
selectedLayer,
|
||||
@@ -49,6 +49,7 @@ export function SideBar() {
|
||||
onclick: () => {
|
||||
selectedLayer.val = key;
|
||||
imagePrompts.val = imagePromptsMulti.val[key];
|
||||
drawSegment(getClicks());
|
||||
},
|
||||
},
|
||||
key,
|
||||
|
||||
@@ -16,6 +16,7 @@ import { api } from "./api.js";
|
||||
import { Container } from "./Container.js";
|
||||
import { loadNpyTensor } from "./onnx.js";
|
||||
import "https://code.iconify.design/3/3.1.0/iconify.min.js";
|
||||
import { drawSegment, getClicks } from "./ImageEditor.js";
|
||||
|
||||
/** @type {import( '../../../web/types/litegraph.js').LGraphGroup} */
|
||||
const recomputeInsideNodesOps = LGraphGroup.prototype.recomputeInsideNodes;
|
||||
@@ -267,6 +268,7 @@ function showMyImageEditor(node) {
|
||||
);
|
||||
loadNpyTensor(embeedingUrl).then((tensor) => {
|
||||
embeddings.val = tensor;
|
||||
drawSegment(getClicks());
|
||||
});
|
||||
targetNode.val = node;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user