PyTorch Hub crops = results.crop() return values (#3282)
* Changing save_one_box Made to work with other changes to common.py * PEP8 and single line BGR Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
1 parent
0e2f2cbb51
commit
a039b7796d
1 file changed
+6
-4
+6
-4
@@ -657,8 +657,8 @@ def apply_classifier(x, model, img, im0):
|
|||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
||||||
def save_one_box(xyxy, im, file='image.jpg', gain=1.02, pad=10, square=False, BGR=False):
|
def save_one_box(xyxy, im, file='image.jpg', gain=1.02, pad=10, square=False, BGR=False, save=True):
|
||||||
# Save an image crop as {file} with crop size multiplied by {gain} and padded by {pad} pixels
|
# Save image crop as {file} with crop size multiple {gain} and {pad} pixels. Save and/or return crop
|
||||||
xyxy = torch.tensor(xyxy).view(-1, 4)
|
xyxy = torch.tensor(xyxy).view(-1, 4)
|
||||||
b = xyxy2xywh(xyxy) # boxes
|
b = xyxy2xywh(xyxy) # boxes
|
||||||
if square:
|
if square:
|
||||||
@@ -666,8 +666,10 @@ def save_one_box(xyxy, im, file='image.jpg', gain=1.02, pad=10, square=False, BG
|
|||||||
b[:, 2:] = b[:, 2:] * gain + pad # box wh * gain + pad
|
b[:, 2:] = b[:, 2:] * gain + pad # box wh * gain + pad
|
||||||
xyxy = xywh2xyxy(b).long()
|
xyxy = xywh2xyxy(b).long()
|
||||||
clip_coords(xyxy, im.shape)
|
clip_coords(xyxy, im.shape)
|
||||||
crop = im[int(xyxy[0, 1]):int(xyxy[0, 3]), int(xyxy[0, 0]):int(xyxy[0, 2])]
|
crop = im[int(xyxy[0, 1]):int(xyxy[0, 3]), int(xyxy[0, 0]):int(xyxy[0, 2]), ::(1 if BGR else -1)]
|
||||||
cv2.imwrite(str(increment_path(file, mkdir=True).with_suffix('.jpg')), crop if BGR else crop[..., ::-1])
|
if save:
|
||||||
|
cv2.imwrite(str(increment_path(file, mkdir=True).with_suffix('.jpg')), crop)
|
||||||
|
return crop
|
||||||
|
|
||||||
|
|
||||||
def increment_path(path, exist_ok=False, sep='', mkdir=False):
|
def increment_path(path, exist_ok=False, sep='', mkdir=False):
|
||||||
|
|||||||
Reference in new issue
Block a user