glenn-jocher commited on
Commit
25f8ab8
1 Parent(s): d6a71ae

detect.py streaming source `--save-crop` bug fix (#3102)

Browse files

* detect.py streaming source --save-crop bug fix

Possible fix for #3100.

* () parenthesis

Files changed (1) hide show
  1. detect.py +2 -1
detect.py CHANGED
@@ -87,6 +87,7 @@ def detect(opt):
87
  txt_path = str(save_dir / 'labels' / p.stem) + ('' if dataset.mode == 'image' else f'_{frame}') # img.txt
88
  s += '%gx%g ' % img.shape[2:] # print string
89
  gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] # normalization gain whwh
 
90
  if len(det):
91
  # Rescale boxes from img_size to im0 size
92
  det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round()
@@ -109,7 +110,7 @@ def detect(opt):
109
  label = None if opt.hide_labels else (names[c] if opt.hide_conf else f'{names[c]} {conf:.2f}')
110
  plot_one_box(xyxy, im0, label=label, color=colors(c, True), line_thickness=opt.line_thickness)
111
  if opt.save_crop:
112
- save_one_box(xyxy, im0s, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True)
113
 
114
  # Print time (inference + NMS)
115
  print(f'{s}Done. ({t2 - t1:.3f}s)')
 
87
  txt_path = str(save_dir / 'labels' / p.stem) + ('' if dataset.mode == 'image' else f'_{frame}') # img.txt
88
  s += '%gx%g ' % img.shape[2:] # print string
89
  gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] # normalization gain whwh
90
+ imc = im0.copy() if opt.save_crop else im0 # for opt.save_crop
91
  if len(det):
92
  # Rescale boxes from img_size to im0 size
93
  det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round()
 
110
  label = None if opt.hide_labels else (names[c] if opt.hide_conf else f'{names[c]} {conf:.2f}')
111
  plot_one_box(xyxy, im0, label=label, color=colors(c, True), line_thickness=opt.line_thickness)
112
  if opt.save_crop:
113
+ save_one_box(xyxy, imc, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True)
114
 
115
  # Print time (inference + NMS)
116
  print(f'{s}Done. ({t2 - t1:.3f}s)')