fix: auto segments not shown

This commit is contained in:
Radionic
2023-11-16 19:02:29 +08:00
parent 8fedf27435
commit 5663ff9e36
2 changed files with 16 additions and 14 deletions
+8 -11
View File
@@ -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();
+8 -3
View File
@@ -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;