Spaces:
Runtime error
Runtime error
support undetected nodes
Browse files- app.py +1 -1
- static/poseEditor.js +18 -11
app.py
CHANGED
@@ -95,7 +95,7 @@ with gr.Blocks() as demo:
|
|
95 |
| Import | Paste json to "Json source" and click "Import Json", edit the width/height, then click "Start edit". |
|
96 |
| Export | click "Save" and "Copy to clipboard" of "Json" section. |
|
97 |
""")
|
98 |
-
json = gr.JSON(label="Json"
|
99 |
jsonInput = gr.Textbox(label="Json source", lines=10)
|
100 |
jsonInputBtn = gr.Button(value="Import Json")
|
101 |
with gr.Column(scale=2):
|
|
|
95 |
| Import | Paste json to "Json source" and click "Import Json", edit the width/height, then click "Start edit". |
|
96 |
| Export | click "Save" and "Copy to clipboard" of "Json" section. |
|
97 |
""")
|
98 |
+
json = gr.JSON(label="Json")
|
99 |
jsonInput = gr.Textbox(label="Json source", lines=10)
|
100 |
jsonInputBtn = gr.Button(value="Import Json")
|
101 |
with gr.Column(scale=2):
|
static/poseEditor.js
CHANGED
@@ -25,7 +25,8 @@ const sampleSubsetElementSource = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
|
25 |
function makePoseFromCandidateAndSubsetElement(candidate, subsetElement) {
|
26 |
var pose = [];
|
27 |
for (let j = 0 ; j < 18; j++) {
|
28 |
-
|
|
|
29 |
}
|
30 |
return pose;
|
31 |
}
|
@@ -93,8 +94,11 @@ function drawBodyPose() {
|
|
93 |
|
94 |
// edge
|
95 |
for (let j = 0; j < 17; j++) {
|
96 |
-
const
|
97 |
-
const
|
|
|
|
|
|
|
98 |
ctx.beginPath();
|
99 |
ctx.lineWidth=stickWidth;
|
100 |
ctx.strokeStyle = `rgb(${colors[j].join(',')})`;
|
@@ -106,7 +110,9 @@ function drawBodyPose() {
|
|
106 |
// node
|
107 |
ctx.font = '12px serif';
|
108 |
for (let j = 0; j < 18; j++) {
|
109 |
-
const
|
|
|
|
|
110 |
ctx.beginPath();
|
111 |
ctx.arc(x, y, stickWidth*1.2, 0, 2 * Math.PI);
|
112 |
ctx.fillStyle = `rgb(${colors[j].join(',')})`;
|
@@ -150,7 +156,9 @@ function getNearestNode(p) {
|
|
150 |
for (let i = 0; i < poseData.length; i++) {
|
151 |
const pose = poseData[i];
|
152 |
for (let j = 0; j < pose.length; j++) {
|
153 |
-
const
|
|
|
|
|
154 |
if (d < minDistSq) {
|
155 |
minDistSq = d;
|
156 |
personIndex = i;
|
@@ -233,8 +241,9 @@ function handleMouseDown(event) {
|
|
233 |
|
234 |
if (event.altKey || event.ctrlKey || event.shiftKey) {
|
235 |
// dragMarksを設定
|
236 |
-
dragMarks[personIndex] =
|
237 |
-
|
|
|
238 |
if (event.altKey) {
|
239 |
dragMode = "move";
|
240 |
} else if (event.ctrlKey) {
|
@@ -245,8 +254,8 @@ function handleMouseDown(event) {
|
|
245 |
}
|
246 |
} else if (keyDownFlags["Space"]) {
|
247 |
dragMarks[personIndex] =
|
248 |
-
|
249 |
-
(node) => distSq(p, node) < dragRange ** 2);
|
250 |
isDragging = dragMarks[personIndex].some((mark) => mark);
|
251 |
dragMode = "move";
|
252 |
} else if (minDist < 16) {
|
@@ -277,9 +286,7 @@ function handleMouseMove(event) {
|
|
277 |
rotateBaseVector = dragOffset;
|
278 |
if (!event.shiftKey) {
|
279 |
dragMode = "rotate2";
|
280 |
-
console.log("rotate2");
|
281 |
}
|
282 |
-
console.log("!");
|
283 |
} else if (dragMode == "rotate2") {
|
284 |
// 回転
|
285 |
let angle = directedAngleTo(rotateBaseVector, dragOffset);
|
|
|
25 |
function makePoseFromCandidateAndSubsetElement(candidate, subsetElement) {
|
26 |
var pose = [];
|
27 |
for (let j = 0 ; j < 18; j++) {
|
28 |
+
let i = subsetElement[j];
|
29 |
+
pose.push(i < 0 ? null : candidate[i]);
|
30 |
}
|
31 |
return pose;
|
32 |
}
|
|
|
94 |
|
95 |
// edge
|
96 |
for (let j = 0; j < 17; j++) {
|
97 |
+
const p = pose[limbSeq[j][0]-1];
|
98 |
+
const q = pose[limbSeq[j][1]-1];
|
99 |
+
if (p == null || q == null) continue;
|
100 |
+
const [X0, Y0] = p;
|
101 |
+
const [X1, Y1] = q;
|
102 |
ctx.beginPath();
|
103 |
ctx.lineWidth=stickWidth;
|
104 |
ctx.strokeStyle = `rgb(${colors[j].join(',')})`;
|
|
|
110 |
// node
|
111 |
ctx.font = '12px serif';
|
112 |
for (let j = 0; j < 18; j++) {
|
113 |
+
const p = pose[j];
|
114 |
+
if (p == null) continue;
|
115 |
+
const [x, y] = p;
|
116 |
ctx.beginPath();
|
117 |
ctx.arc(x, y, stickWidth*1.2, 0, 2 * Math.PI);
|
118 |
ctx.fillStyle = `rgb(${colors[j].join(',')})`;
|
|
|
156 |
for (let i = 0; i < poseData.length; i++) {
|
157 |
const pose = poseData[i];
|
158 |
for (let j = 0; j < pose.length; j++) {
|
159 |
+
const q = pose[j];
|
160 |
+
if (q == null) continue;
|
161 |
+
const d = distSq(p, q);
|
162 |
if (d < minDistSq) {
|
163 |
minDistSq = d;
|
164 |
personIndex = i;
|
|
|
241 |
|
242 |
if (event.altKey || event.ctrlKey || event.shiftKey) {
|
243 |
// dragMarksを設定
|
244 |
+
dragMarks[personIndex] =
|
245 |
+
poseData[personIndex].map((node) => node != null);
|
246 |
+
isDragging = true;
|
247 |
if (event.altKey) {
|
248 |
dragMode = "move";
|
249 |
} else if (event.ctrlKey) {
|
|
|
254 |
}
|
255 |
} else if (keyDownFlags["Space"]) {
|
256 |
dragMarks[personIndex] =
|
257 |
+
poseData[personIndex].map(
|
258 |
+
(node) => node != null && distSq(p, node) < dragRange ** 2);
|
259 |
isDragging = dragMarks[personIndex].some((mark) => mark);
|
260 |
dragMode = "move";
|
261 |
} else if (minDist < 16) {
|
|
|
286 |
rotateBaseVector = dragOffset;
|
287 |
if (!event.shiftKey) {
|
288 |
dragMode = "rotate2";
|
|
|
289 |
}
|
|
|
290 |
} else if (dragMode == "rotate2") {
|
291 |
// 回転
|
292 |
let angle = directedAngleTo(rotateBaseVector, dragOffset);
|