vchiang001 commited on
Commit
2b6769d
β€’
1 Parent(s): d81c118

added choice of fonts

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -23,12 +23,21 @@ import yaml
23
 
24
  #########################################
25
 
 
 
 
 
 
 
 
 
26
  def draw_keypoints_on_image(image,
27
  keypoints,
28
  map_label_id_to_str,
29
  color='red',
30
  radius=2,
31
  use_normalized_coordinates=True,
 
32
  ):
33
  """Draws keypoints on an image.
34
  Modified from:
@@ -43,7 +52,7 @@ def draw_keypoints_on_image(image,
43
  """
44
  # get a drawing context
45
  draw = ImageDraw.Draw(image)
46
- # font = ImageFont.truetype("sans-serif.ttf", 16)
47
 
48
  im_width, im_height = image.size
49
  keypoints_x = [k[0] for k in keypoints]
@@ -55,7 +64,7 @@ def draw_keypoints_on_image(image,
55
  keypoints_y = tuple([im_height * y for y in keypoints_y])
56
 
57
  # draw ellipses around keypoints and add string labels
58
- font = ImageFont.truetype("font/Amiko-Regular.ttf", 8) # font = ImageFont.truetype(<font-file>, <font-size>)
59
  for i, (keypoint_x, keypoint_y) in enumerate(zip(keypoints_x, keypoints_y)):
60
  draw.ellipse([(keypoint_x - radius, keypoint_y - radius),
61
  (keypoint_x + radius, keypoint_y + radius)],
@@ -158,7 +167,9 @@ def predict_pipeline(img_input,
158
  model_input_str,
159
  flag_dlc_only,
160
  bbox_likelihood_th,
161
- kpts_likelihood_th):
 
 
162
 
163
  ############################################################
164
  ## Get DLC model and labels as strings
@@ -210,7 +221,9 @@ def predict_pipeline(img_input,
210
  map_label_id_to_str,
211
  color='red',
212
  radius=2,
213
- use_normalized_coordinates=False)
 
 
214
  return img_input, #list_kpts_per_crop
215
 
216
  else:
@@ -233,6 +246,7 @@ def predict_pipeline(img_input,
233
  color='red',
234
  radius=2,
235
  use_normalized_coordinates=False, # if True, then I should use md_results.xyxyn
 
236
  )
237
 
238
  ## Paste crop in original image
@@ -282,7 +296,7 @@ inputs = [gr_image_input,
282
  gr_slider_conf_bboxes,
283
  gr_slider_conf_keypoints,
284
  #gr_keypt_color,
285
- #gr_pose_font_input,
286
  #gr_slider_font_size,
287
  ]
288
 
@@ -314,7 +328,8 @@ demo = gr.Interface(predict_pipeline,
314
  title=gr_title,
315
  description=gr_description,
316
  theme="huggingface",
317
- live=True)
 
318
 
319
  demo.launch(enable_queue=True)
320
 
 
23
 
24
  #########################################
25
 
26
+
27
+ FONTS = {'amiko': "font/Amiko-Regular.ttf",
28
+ 'nature': "font/LoveNature.otf",
29
+ 'painter':"font/PainterDecorator.otf",
30
+ 'animals': "font/UncialAnimals.ttf",
31
+ 'zen': "font/ZEN.TTF"}
32
+
33
+
34
  def draw_keypoints_on_image(image,
35
  keypoints,
36
  map_label_id_to_str,
37
  color='red',
38
  radius=2,
39
  use_normalized_coordinates=True,
40
+ gr_pose_font_input,
41
  ):
42
  """Draws keypoints on an image.
43
  Modified from:
 
52
  """
53
  # get a drawing context
54
  draw = ImageDraw.Draw(image)
55
+ # font = ImageFont.truetype("sans-serif.ttf", 16)
56
 
57
  im_width, im_height = image.size
58
  keypoints_x = [k[0] for k in keypoints]
 
64
  keypoints_y = tuple([im_height * y for y in keypoints_y])
65
 
66
  # draw ellipses around keypoints and add string labels
67
+ font = ImageFont.truetype(FONTS[gr_pose_font_input], 8) # font = ImageFont.truetype(<font-file>, <font-size>)
68
  for i, (keypoint_x, keypoint_y) in enumerate(zip(keypoints_x, keypoints_y)):
69
  draw.ellipse([(keypoint_x - radius, keypoint_y - radius),
70
  (keypoint_x + radius, keypoint_y + radius)],
 
167
  model_input_str,
168
  flag_dlc_only,
169
  bbox_likelihood_th,
170
+ kpts_likelihood_th,
171
+ gr_pose_font_input,
172
+ ):
173
 
174
  ############################################################
175
  ## Get DLC model and labels as strings
 
221
  map_label_id_to_str,
222
  color='red',
223
  radius=2,
224
+ use_normalized_coordinates=False,
225
+ gr_pose_font_input
226
+ )
227
  return img_input, #list_kpts_per_crop
228
 
229
  else:
 
246
  color='red',
247
  radius=2,
248
  use_normalized_coordinates=False, # if True, then I should use md_results.xyxyn
249
+ gr_pose_font_input,
250
  )
251
 
252
  ## Paste crop in original image
 
296
  gr_slider_conf_bboxes,
297
  gr_slider_conf_keypoints,
298
  #gr_keypt_color,
299
+ gr_pose_font_input,
300
  #gr_slider_font_size,
301
  ]
302
 
 
328
  title=gr_title,
329
  description=gr_description,
330
  theme="huggingface",
331
+ #live=True
332
+ )
333
 
334
  demo.launch(enable_queue=True)
335