detect.py streaming source `--save-crop` bug fix (#3102)
* detect.py streaming source --save-crop bug fix Possible fix for #3100. * () parenthesis
This commit is contained in:
parent
d6a71ae5f2
commit
25f8ab835e
|
|
@ -87,6 +87,7 @@ def detect(opt):
|
||||||
txt_path = str(save_dir / 'labels' / p.stem) + ('' if dataset.mode == 'image' else f'_{frame}') # img.txt
|
txt_path = str(save_dir / 'labels' / p.stem) + ('' if dataset.mode == 'image' else f'_{frame}') # img.txt
|
||||||
s += '%gx%g ' % img.shape[2:] # print string
|
s += '%gx%g ' % img.shape[2:] # print string
|
||||||
gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] # normalization gain whwh
|
gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] # normalization gain whwh
|
||||||
|
imc = im0.copy() if opt.save_crop else im0 # for opt.save_crop
|
||||||
if len(det):
|
if len(det):
|
||||||
# Rescale boxes from img_size to im0 size
|
# Rescale boxes from img_size to im0 size
|
||||||
det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round()
|
det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round()
|
||||||
|
|
@ -109,7 +110,7 @@ def detect(opt):
|
||||||
label = None if opt.hide_labels else (names[c] if opt.hide_conf else f'{names[c]} {conf:.2f}')
|
label = None if opt.hide_labels else (names[c] if opt.hide_conf else f'{names[c]} {conf:.2f}')
|
||||||
plot_one_box(xyxy, im0, label=label, color=colors(c, True), line_thickness=opt.line_thickness)
|
plot_one_box(xyxy, im0, label=label, color=colors(c, True), line_thickness=opt.line_thickness)
|
||||||
if opt.save_crop:
|
if opt.save_crop:
|
||||||
save_one_box(xyxy, im0s, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True)
|
save_one_box(xyxy, imc, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True)
|
||||||
|
|
||||||
# Print time (inference + NMS)
|
# Print time (inference + NMS)
|
||||||
print(f'{s}Done. ({t2 - t1:.3f}s)')
|
print(f'{s}Done. ({t2 - t1:.3f}s)')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue