Spaces:
Build error
Build error
add background
Browse files- js/poseMaker.js +19 -0
- main.py +9 -10
- pose.py +0 -2
js/poseMaker.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
console.log("hello from poseEditor.js")
|
| 2 |
var canvas = null;
|
| 3 |
var ctx = null;
|
|
|
|
| 4 |
|
| 5 |
const wheelDisplayTime = 500;
|
| 6 |
|
|
@@ -176,6 +177,12 @@ function clearCanvas() {
|
|
| 176 |
ctx.fillRect(0, 0, w, h);
|
| 177 |
}
|
| 178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
function resizeCanvas(width, height) {
|
| 180 |
canvas.width = width ? width : canvas.width;
|
| 181 |
canvas.height = height ? height : canvas.height;
|
|
@@ -347,6 +354,7 @@ function drawUI() {
|
|
| 347 |
|
| 348 |
function Redraw() {
|
| 349 |
clearCanvas();
|
|
|
|
| 350 |
drawBodyPose();
|
| 351 |
drawUI();
|
| 352 |
}
|
|
@@ -554,6 +562,8 @@ function handleMouseUp(event) {
|
|
| 554 |
|
| 555 |
function handleMouseLeave(event) {
|
| 556 |
mouseCursor = [-1,-1];
|
|
|
|
|
|
|
| 557 |
}
|
| 558 |
|
| 559 |
function ModifyDragRange(delta) { dragRange = Math.max(dragRangeDelta, Math.min(512, dragRange + delta)); }
|
|
@@ -792,3 +802,12 @@ function savePose() {
|
|
| 792 |
|
| 793 |
return jsonData;
|
| 794 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
console.log("hello from poseEditor.js")
|
| 2 |
var canvas = null;
|
| 3 |
var ctx = null;
|
| 4 |
+
var canvasBg = null;
|
| 5 |
|
| 6 |
const wheelDisplayTime = 500;
|
| 7 |
|
|
|
|
| 177 |
ctx.fillRect(0, 0, w, h);
|
| 178 |
}
|
| 179 |
|
| 180 |
+
function drawBackground() {
|
| 181 |
+
if (canvasBg != null) {
|
| 182 |
+
ctx.drawImage(canvasBg, 0, 0);
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
function resizeCanvas(width, height) {
|
| 187 |
canvas.width = width ? width : canvas.width;
|
| 188 |
canvas.height = height ? height : canvas.height;
|
|
|
|
| 354 |
|
| 355 |
function Redraw() {
|
| 356 |
clearCanvas();
|
| 357 |
+
drawBackground();
|
| 358 |
drawBodyPose();
|
| 359 |
drawUI();
|
| 360 |
}
|
|
|
|
| 562 |
|
| 563 |
function handleMouseLeave(event) {
|
| 564 |
mouseCursor = [-1,-1];
|
| 565 |
+
handleMouseUp(event);
|
| 566 |
+
keyDownFlags = {};
|
| 567 |
}
|
| 568 |
|
| 569 |
function ModifyDragRange(delta) { dragRange = Math.max(dragRangeDelta, Math.min(512, dragRange + delta)); }
|
|
|
|
| 802 |
|
| 803 |
return jsonData;
|
| 804 |
}
|
| 805 |
+
|
| 806 |
+
function importBackground(image) {
|
| 807 |
+
let m = new Image();
|
| 808 |
+
m.src = image;
|
| 809 |
+
m.onload = function() {
|
| 810 |
+
canvasBg = m;
|
| 811 |
+
Redraw();
|
| 812 |
+
}
|
| 813 |
+
}
|
main.py
CHANGED
|
@@ -18,7 +18,6 @@ def image_changed(image):
|
|
| 18 |
else:
|
| 19 |
print("pose not found")
|
| 20 |
pose_result, returned_outputs = infer(util.pil2cv(image))
|
| 21 |
-
print(len(pose_result))
|
| 22 |
|
| 23 |
candidate = []
|
| 24 |
subset = []
|
|
@@ -32,20 +31,12 @@ def image_changed(image):
|
|
| 32 |
candidate.extend(util.convert_keypoints(keypoints))
|
| 33 |
m = len(candidate)
|
| 34 |
subset.append([j for j in range(n, m)])
|
| 35 |
-
print("=====")
|
| 36 |
-
print(candidate)
|
| 37 |
-
print(subset)
|
| 38 |
|
| 39 |
jsonText = "{ \"candidate\": " + util.candidate_to_json_string(candidate) + ", \"subset\": " + util.subset_to_json_string(subset) + " }"
|
| 40 |
-
print(jsonText)
|
| 41 |
return f"""{image.width}px x {image.height}px, {len(subset)} indivisual(s)""", jsonText
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
return draw(image, pose_result)
|
| 46 |
-
|
| 47 |
html_text = f"""
|
| 48 |
-
<canvas id="canvas" width="512" height="512"></canvas
|
| 49 |
"""
|
| 50 |
|
| 51 |
with gr.Blocks(css="""button { min-width: 80px; }""") as demo:
|
|
@@ -63,6 +54,8 @@ with gr.Blocks(css="""button { min-width: 80px; }""") as demo:
|
|
| 63 |
replaceBtn = gr.Button(value="Replace")
|
| 64 |
with gr.Column(min_width=80):
|
| 65 |
importBtn = gr.Button(value="Import")
|
|
|
|
|
|
|
| 66 |
with gr.Accordion(label="Json", open=False):
|
| 67 |
with gr.Row():
|
| 68 |
with gr.Column(min_width=80):
|
|
@@ -139,6 +132,12 @@ When using Q, X, C, R, pressing and dont release until the operation is complete
|
|
| 139 |
inputs = [json],
|
| 140 |
outputs = [],
|
| 141 |
_js="(json) => { importPose(json); return []; }")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
saveBtn.click(
|
| 144 |
fn = None,
|
|
|
|
| 18 |
else:
|
| 19 |
print("pose not found")
|
| 20 |
pose_result, returned_outputs = infer(util.pil2cv(image))
|
|
|
|
| 21 |
|
| 22 |
candidate = []
|
| 23 |
subset = []
|
|
|
|
| 31 |
candidate.extend(util.convert_keypoints(keypoints))
|
| 32 |
m = len(candidate)
|
| 33 |
subset.append([j for j in range(n, m)])
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
jsonText = "{ \"candidate\": " + util.candidate_to_json_string(candidate) + ", \"subset\": " + util.subset_to_json_string(subset) + " }"
|
|
|
|
| 36 |
return f"""{image.width}px x {image.height}px, {len(subset)} indivisual(s)""", jsonText
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
html_text = f"""
|
| 39 |
+
<canvas id="canvas" width="512" height="512"></canvas><img id="canvas-background" style="display:none;"/>
|
| 40 |
"""
|
| 41 |
|
| 42 |
with gr.Blocks(css="""button { min-width: 80px; }""") as demo:
|
|
|
|
| 54 |
replaceBtn = gr.Button(value="Replace")
|
| 55 |
with gr.Column(min_width=80):
|
| 56 |
importBtn = gr.Button(value="Import")
|
| 57 |
+
with gr.Column(min_width=80):
|
| 58 |
+
bgBtn = gr.Button(value="Background")
|
| 59 |
with gr.Accordion(label="Json", open=False):
|
| 60 |
with gr.Row():
|
| 61 |
with gr.Column(min_width=80):
|
|
|
|
| 132 |
inputs = [json],
|
| 133 |
outputs = [],
|
| 134 |
_js="(json) => { importPose(json); return []; }")
|
| 135 |
+
bgBtn.click(
|
| 136 |
+
fn = None,
|
| 137 |
+
inputs = [source],
|
| 138 |
+
outputs = [],
|
| 139 |
+
_js="(image) => { importBackground(image); return []; }"
|
| 140 |
+
)
|
| 141 |
|
| 142 |
saveBtn.click(
|
| 143 |
fn = None,
|
pose.py
CHANGED
|
@@ -31,8 +31,6 @@ def infer(image):
|
|
| 31 |
dataset_info=dataset_info,
|
| 32 |
return_heatmap=False,
|
| 33 |
outputs=None)
|
| 34 |
-
print(pose_results)
|
| 35 |
-
print(returned_outputs)
|
| 36 |
|
| 37 |
return pose_results, returned_outputs
|
| 38 |
|
|
|
|
| 31 |
dataset_info=dataset_info,
|
| 32 |
return_heatmap=False,
|
| 33 |
outputs=None)
|
|
|
|
|
|
|
| 34 |
|
| 35 |
return pose_results, returned_outputs
|
| 36 |
|