From 5663ff9e36da98e654d0d23dd3b95e090ebc605a Mon Sep 17 00:00:00 2001 From: Radionic Date: Thu, 16 Nov 2023 19:02:29 +0800 Subject: [PATCH] fix: auto segments not shown --- js/LayerEditor.js | 19 ++++++++----------- js/index.js | 11 ++++++++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/js/LayerEditor.js b/js/LayerEditor.js index 4eab270..f2e8730 100644 --- a/js/LayerEditor.js +++ b/js/LayerEditor.js @@ -42,13 +42,13 @@ const faceLandmarker = await FaceLandmarker.createFromOptions(filesetResolver, { const layerMapping = { L_eye: { useMiddle: false, - positiveOffset: 0.1, + positiveOffset: 0, negativeOffset: 0.5, indices: FaceLandmarker.FACE_LANDMARKS_RIGHT_EYE, }, R_eye: { useMiddle: false, - positiveOffset: 0.1, + positiveOffset: 0, negativeOffset: 0.5, indices: FaceLandmarker.FACE_LANDMARKS_LEFT_EYE, }, @@ -84,14 +84,12 @@ const layerMapping = { }, }; -async function drawPoints(part) {} - -async function autoSegment() { +export async function autoSegment() { const image = document.getElementById("image"); const landmarks = faceLandmarker.detect(image).faceLandmarks[0]; - Object.entries(layerMapping).forEach(([key, value]) => { - imagePromptsMulti.val[key] = []; - }); + // Object.entries(layerMapping).forEach(([key, value]) => { + // imagePromptsMulti.val[key] = []; + // }); Object.entries(layerMapping).forEach(([key, value]) => { const positivePoints = []; @@ -101,7 +99,7 @@ async function autoSegment() { // Positive points for (const { start, end } of value.indices) { const startPoint = landmarks[start]; - const endPoint = landmarks[end]; + // const endPoint = landmarks[end]; const startX = startPoint.x * imageSize.val.width; const startY = startPoint.y * imageSize.val.height; @@ -190,6 +188,7 @@ async function autoSegment() { ]; } }); + imagePrompts.val = imagePromptsMulti.val[selectedLayer.val]; console.log("Done"); } @@ -435,8 +434,6 @@ export function LayerEditor() { const canvas = document.getElementById("mask-canvas"); canvas.width = e.target.naturalWidth; canvas.height = e.target.naturalHeight; - - await autoSegment(); }, oncontextmenu: async (e) => { e.preventDefault(); diff --git a/js/index.js b/js/index.js index 2d5ff99..6955d7f 100644 --- a/js/index.js +++ b/js/index.js @@ -23,7 +23,7 @@ import { api } from "./api.js"; import { Container } from "./Container.js"; import { initModel, loadNpyTensor } from "./onnx.js"; import "https://code.iconify.design/3/3.1.0/iconify.min.js"; -import { drawSegment, getClicks } from "./LayerEditor.js"; +import { autoSegment, drawSegment, getClicks } from "./LayerEditor.js"; import { infoDialog } from "./dialog.js"; export const generatedImages = {}; @@ -274,7 +274,11 @@ function getInputWidgetValue(node, inputIndex, widgetName) { * @param {LGraphNode} node */ function showMyImageEditor(node) { - let [isGeneratedImage, connectedImageFileName] = getInputWidgetValue(node, 0, "image"); + let [isGeneratedImage, connectedImageFileName] = getInputWidgetValue( + node, + 0, + "image" + ); if (!connectedImageFileName) { alertDialog.val = { text: "Please connect or generate an image first", @@ -338,8 +342,9 @@ function showMyImageEditor(node) { `${id}_${modelType}.npy` )}&type=output&subfolder=` ); - loadNpyTensor(embeedingUrl).then((tensor) => { + loadNpyTensor(embeedingUrl).then(async (tensor) => { embeddings.val = tensor; + await autoSegment(); drawSegment(getClicks()); }); targetNode.val = node;