sabrinabenas commited on
Commit
59b822b
β€’
1 Parent(s): 3c2de81

add bb and text aprox

Browse files
Files changed (1) hide show
  1. app.py +19 -1
app.py CHANGED
@@ -160,6 +160,23 @@ def crop_animal_detections(img_in,
160
 
161
  return list_np_animal_crops
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  ##########################################
164
  def predict_dlc(list_np_crops,
165
  kpts_likelihood_th,
@@ -286,7 +303,8 @@ def predict_pipeline(img_input,
286
  ## Paste crop in original image https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.paste
287
  img_background.paste(img_crop,
288
  box = tuple([int(t) for t in md_results.xyxy[0][ic,:2]]))
289
-
 
290
  return img_background
291
 
292
  #############################################
 
160
 
161
  return list_np_animal_crops
162
 
163
+ def draw_rectangle_text(img,results,font_style='amiko',font_size=8,):
164
+ bbxyxy = results.xyxy[0].tolist()[0]
165
+ w, h = bbxyxy[2], bbxyxy[3]
166
+ shape = [(bbxyxy[0], bbxyxy[1]), (w , h)]
167
+ imgR = ImageDraw.Draw(img)
168
+ imgR.rectangle(shape, outline ="red",width=5)
169
+
170
+ confidence = bbxyxy[4]
171
+ print(confidence)
172
+ font = ImageFont.truetype(FONTS[font_style], font_size)
173
+ imgR.text((keypoint_x + marker_size, keypoint_y + marker_size),#(0.5*im_width, 0.5*im_height), #-------
174
+ map_label_id_to_str[i],
175
+ ImageColor.getcolor(keypt_color, "RGB"), # rgb
176
+ font=font)
177
+
178
+ return imgR
179
+
180
  ##########################################
181
  def predict_dlc(list_np_crops,
182
  kpts_likelihood_th,
 
303
  ## Paste crop in original image https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.paste
304
  img_background.paste(img_crop,
305
  box = tuple([int(t) for t in md_results.xyxy[0][ic,:2]]))
306
+
307
+ draw_rectangle_text(img_background, md_results)
308
  return img_background
309
 
310
  #############################################