Akjava commited on
Commit
a3e2355
·
1 Parent(s): 3d05296

fix square support

Browse files
Files changed (2) hide show
  1. app.py +7 -8
  2. mp_box.py +5 -0
app.py CHANGED
@@ -28,6 +28,10 @@ def process_images(image,no_mesh_draw=False,square_shape=False,progress=gr.Progr
28
  progress(0, desc="Start Mediapipe")
29
 
30
  boxes,mp_image,face_landmarker_result = mp_box.mediapipe_to_box(image)
 
 
 
 
31
  if no_mesh_draw:
32
  annotated_image = image
33
  else:
@@ -39,22 +43,17 @@ def process_images(image,no_mesh_draw=False,square_shape=False,progress=gr.Progr
39
  }
40
  index = 1
41
 
42
- print(boxes)
43
  if square_shape:
44
  xy_boxes = boxes[3:]
45
  else:
46
  xy_boxes = boxes[:3]
47
 
48
- print(len(xy_boxes))
49
  for box in xy_boxes:
50
  label=f"type-{index}"
51
- print(box)
52
- print(mp_box.xywh_to_xyxy(box))
53
  annotation_boxes.append([mp_box.xywh_to_xyxy(box),label])
54
 
55
 
56
  jsons[label] = boxes[index-1]
57
- print(index)
58
  index+=1
59
 
60
  annotation_boxes.append(([0,0,1,1],"None"))
@@ -124,12 +123,12 @@ with gr.Blocks(css=css, elem_id="demo-container") as demo:
124
 
125
 
126
 
127
- btn.click(fn=process_images, inputs=[image,no_mesh_draw], outputs =[image_out,text_out], api_name='infer')
128
  gr.Examples(
129
  examples =["examples/00004200.jpg"],
130
  inputs=[image]
131
  )
132
  gr.HTML(read_file("demo_footer.html"))
133
 
134
- if __name__ == "__main__":
135
- demo.launch()
 
28
  progress(0, desc="Start Mediapipe")
29
 
30
  boxes,mp_image,face_landmarker_result = mp_box.mediapipe_to_box(image)
31
+ for i in range(len(boxes)):
32
+ boxes[i] = mp_box.to_int_box(boxes[i])
33
+
34
+
35
  if no_mesh_draw:
36
  annotated_image = image
37
  else:
 
43
  }
44
  index = 1
45
 
 
46
  if square_shape:
47
  xy_boxes = boxes[3:]
48
  else:
49
  xy_boxes = boxes[:3]
50
 
 
51
  for box in xy_boxes:
52
  label=f"type-{index}"
 
 
53
  annotation_boxes.append([mp_box.xywh_to_xyxy(box),label])
54
 
55
 
56
  jsons[label] = boxes[index-1]
 
57
  index+=1
58
 
59
  annotation_boxes.append(([0,0,1,1],"None"))
 
123
 
124
 
125
 
126
+ btn.click(fn=process_images, inputs=[image,no_mesh_draw,square_shape], outputs =[image_out,text_out], api_name='infer')
127
  gr.Examples(
128
  examples =["examples/00004200.jpg"],
129
  inputs=[image]
130
  )
131
  gr.HTML(read_file("demo_footer.html"))
132
 
133
+ if __name__ == "__main__":
134
+ demo.launch()
mp_box.py CHANGED
@@ -5,10 +5,15 @@ from mediapipe.framework.formats import landmark_pb2
5
  from mediapipe import solutions
6
  import numpy as np
7
 
 
 
8
  # for X,Y,W,H to x1,y1,x2,y2(Left-top,right-bottom style)
9
  def xywh_to_xyxy(box):
10
  return [box[0],box[1],box[0]+box[2],box[1]+box[3]]
11
 
 
 
 
12
  def convert_to_box(face_landmarks_list,indices,w=1024,h=1024):
13
  x1=w
14
  y1=h
 
5
  from mediapipe import solutions
6
  import numpy as np
7
 
8
+ # heavy changed in gradio app
9
+
10
  # for X,Y,W,H to x1,y1,x2,y2(Left-top,right-bottom style)
11
  def xywh_to_xyxy(box):
12
  return [box[0],box[1],box[0]+box[2],box[1]+box[3]]
13
 
14
+ def to_int_box(box):
15
+ return [int(box[0]),int(box[1]),int(box[2]),int(box[3])]
16
+
17
  def convert_to_box(face_landmarks_list,indices,w=1024,h=1024):
18
  x1=w
19
  y1=h