Zengyf-CVer commited on
Commit
24dd5fd
1 Parent(s): fe9546f

add object crop

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -227,6 +227,12 @@ def yolo_det_img(img, device, model_name, infer_size, conf, iou, max_num, model_
227
  img_size = img.size # frame size
228
 
229
  results = model(img, size=infer_size) # detection
 
 
 
 
 
 
230
 
231
  # Data Frame
232
  dataframe = results.pandas().xyxy[0].round(2)
@@ -320,7 +326,7 @@ def yolo_det_img(img, device, model_name, infer_size, conf, iou, max_num, model_
320
  for k, v in clsDet_dict.items():
321
  clsRatio_dict[k] = v / clsDet_dict_sum
322
 
323
- return det_img, objSize_dict, clsRatio_dict, det_json, report, dataframe
324
 
325
 
326
  # YOLOv5 video detection function
@@ -517,12 +523,13 @@ def main(args):
517
  label="List of detection information")
518
  outputs_objSize = gr.Label(label="Object size ratio statistics")
519
  outputs_clsSize = gr.Label(label="Category detection proportion statistics")
 
520
 
521
  # -------------------output component-------------------
522
  outputs_video = gr.Video(format='mp4', label="Detection video")
523
 
524
  # output parameters
525
- outputs_img_list = [outputs_img, outputs_objSize, outputs_clsSize, outputs_json, outputs_pdf, outputs_df]
526
  outputs_video_list = [outputs_video]
527
 
528
  # title
 
227
  img_size = img.size # frame size
228
 
229
  results = model(img, size=infer_size) # detection
230
+
231
+ # ----------------目标裁剪----------------
232
+ crops = results.crop(save=False)
233
+ img_crops = []
234
+ for i in range(len(crops)):
235
+ img_crops.append(crops[i]["im"][..., ::-1])
236
 
237
  # Data Frame
238
  dataframe = results.pandas().xyxy[0].round(2)
 
326
  for k, v in clsDet_dict.items():
327
  clsRatio_dict[k] = v / clsDet_dict_sum
328
 
329
+ return det_img, objSize_dict, clsRatio_dict, det_json, report, dataframe, img_crops
330
 
331
 
332
  # YOLOv5 video detection function
 
523
  label="List of detection information")
524
  outputs_objSize = gr.Label(label="Object size ratio statistics")
525
  outputs_clsSize = gr.Label(label="Category detection proportion statistics")
526
+ outputs_crops = gr.Gallery(label="Object crop")
527
 
528
  # -------------------output component-------------------
529
  outputs_video = gr.Video(format='mp4', label="Detection video")
530
 
531
  # output parameters
532
+ outputs_img_list = [outputs_img, outputs_objSize, outputs_clsSize, outputs_json, outputs_pdf, outputs_df, outputs_crops]
533
  outputs_video_list = [outputs_video]
534
 
535
  # title