jonigata commited on
Commit
a38a551
1 Parent(s): 9ae3428

use tEXt chunk when pose image given

Browse files
Files changed (2) hide show
  1. app.py +23 -8
  2. static/poseEditor.js +2 -2
app.py CHANGED
@@ -3,6 +3,7 @@ import numpy as np
3
  import cv2
4
  from fastapi import FastAPI, Request, Response
5
  from src.body import Body
 
6
 
7
  body_estimation = Body('model/body_pose_model.pth')
8
 
@@ -69,15 +70,23 @@ def estimate_body(source):
69
  return "{ \"candidate\": " + candidate_to_json_string(candidate) + ", \"subset\": " + subset_to_json_string(subset) + " }"
70
 
71
  def image_changed(image):
72
- if (image == None):
73
  return "estimation", {}
74
 
75
- #json = estimate_body(image)
76
- candidate, subset = body_estimation(pil2cv(image))
77
- print(subset.shape)
78
- json = "{ \"candidate\": " + candidate_to_json_string(candidate) + ", \"subset\": " + subset_to_json_string(subset) + " }"
79
-
80
- return f"""{image.width}px x {image.height}px, {subset.shape[0]} indivisual(s)""", json
 
 
 
 
 
 
 
 
81
 
82
  html_text = f"""
83
  <canvas id="canvas" width="512" height="512"></canvas>
@@ -115,7 +124,13 @@ with gr.Blocks(css="""button { min-width: 80px; }""") as demo:
115
  jsonSource = gr.Textbox(label="Json source", lines=10)
116
  with gr.Accordion(label="Notes", open=False):
117
  gr.Markdown("""
118
- Points to note for pseudo-3D rotation: When performing pseudo-3D rotation on the X and Y axes, the projection is converted to 2D and Z-axis information is lost when the mouse button is released. This means that if you finish dragging while the shape is collapsed, you may not be able to restore it to its original state. In such a case, please use the "undo" function.
 
 
 
 
 
 
119
  """)
120
  with gr.Column(scale=2):
121
  html = gr.HTML(html_text)
 
3
  import cv2
4
  from fastapi import FastAPI, Request, Response
5
  from src.body import Body
6
+ import json as js
7
 
8
  body_estimation = Body('model/body_pose_model.pth')
9
 
 
70
  return "{ \"candidate\": " + candidate_to_json_string(candidate) + ", \"subset\": " + subset_to_json_string(subset) + " }"
71
 
72
  def image_changed(image):
73
+ if image == None:
74
  return "estimation", {}
75
 
76
+ print(js.dumps(image.info, indent=2))
77
+ if 'openpose' in image.info:
78
+ print("pose found")
79
+ jsonText = image.info['openpose']
80
+ print(jsonText)
81
+ jsonObj = js.loads(jsonText)
82
+ subset = jsonObj['subset']
83
+ return f"""{image.width}px x {image.height}px, {len(subset)} indivisual(s)""", jsonText
84
+ else:
85
+ print("pose not found")
86
+ candidate, subset = body_estimation(pil2cv(image))
87
+ print(subset.shape)
88
+ jsonText = "{ \"candidate\": " + candidate_to_json_string(candidate) + ", \"subset\": " + subset_to_json_string(subset) + " }"
89
+ return f"""{image.width}px x {image.height}px, {subset.shape[0]} indivisual(s)""", jsonText
90
 
91
  html_text = f"""
92
  <canvas id="canvas" width="512" height="512"></canvas>
 
124
  jsonSource = gr.Textbox(label="Json source", lines=10)
125
  with gr.Accordion(label="Notes", open=False):
126
  gr.Markdown("""
127
+ #### How to bring pose to ControlNet
128
+ 1. Press **Save** button
129
+ 2. **Drag** the file placed at the bottom left corder of browser
130
+ 3. **Drop** the file into ControlNet
131
+
132
+ #### Points to note for pseudo-3D rotation
133
+ When performing pseudo-3D rotation on the X and Y axes, the projection is converted to 2D and Z-axis information is lost when the mouse button is released. This means that if you finish dragging while the shape is collapsed, you may not be able to restore it to its original state. In such a case, please use the "undo" function.
134
  """)
135
  with gr.Column(scale=2):
136
  html = gr.HTML(html_text)
static/poseEditor.js CHANGED
@@ -89,7 +89,7 @@ function makePoseFromCandidateAndSubsetElement(candidate, subsetElement) {
89
  var pose = [];
90
  for (let j = 0 ; j < 18; j++) {
91
  let i = subsetElement[j];
92
- pose.push(i < 0 ? null : candidate[i].map((x)=>x));
93
  }
94
  return pose;
95
  }
@@ -735,7 +735,7 @@ function savePose() {
735
  var [candidate, subset] = poseDataToCandidateAndSubset(poseData);
736
  let jsonData = {candidate: candidate, subset: subset};
737
 
738
- var url = mergeCanvasWithPose("pose", JSON.stringify(jsonData));
739
 
740
  const createEl = document.createElement('a');
741
  createEl.href = url;
 
89
  var pose = [];
90
  for (let j = 0 ; j < 18; j++) {
91
  let i = subsetElement[j];
92
+ pose.push(i < 0 || candidate[i] == null ? null : candidate[i].map((x)=>x));
93
  }
94
  return pose;
95
  }
 
735
  var [candidate, subset] = poseDataToCandidateAndSubset(poseData);
736
  let jsonData = {candidate: candidate, subset: subset};
737
 
738
+ var url = mergeCanvasWithPose("openpose", JSON.stringify(jsonData));
739
 
740
  const createEl = document.createElement('a');
741
  createEl.href = url;