Skip to content

Commit 6c8a4a7

Browse files
Merge pull request #64 from J4BEZ/patch-1
modify a link of 'requirements.txt' and solve 'save_one_box' not defined
2 parents 6b5b931 + ea4363a commit 6c8a4a7

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This repository contains a highly configurable two-stage-tracker that adjusts to
2929

3030
If you already cloned and forgot to use `--recurse-submodules` you can run `git submodule update --init`
3131

32-
2. Make sure that you fulfill all the requirements: Python 3.8 or later with all [requirements.txt](https://github.com/mikel-brostrom/Yolov7_DeepSort_Pytorch/blob/master/requirements.txt) dependencies installed, including torch>=1.7. To install, run:
32+
2. Make sure that you fulfill all the requirements: Python 3.8 or later with all [requirements.txt](https://github.com/mikel-brostrom/Yolov7_StrongSORT_OSNet/blob/main/requirements.txt) dependencies installed, including torch>=1.7. To install, run:
3333

3434
`pip install -r requirements.txt`
3535

track.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import torch
1515
import torch.backends.cudnn as cudnn
1616
from numpy import random
17-
17+
from PIL import Image
1818

1919
FILE = Path(__file__).resolve()
2020
ROOT = FILE.parents[0] # yolov5 strongsort root directory
@@ -32,13 +32,31 @@
3232
from yolov7.models.experimental import attempt_load
3333
from yolov7.utils.datasets import LoadImages, LoadStreams
3434
from yolov7.utils.general import (check_img_size, non_max_suppression, scale_coords, check_requirements, cv2,
35-
check_imshow, xyxy2xywh, increment_path, strip_optimizer, colorstr, check_file)
35+
check_imshow, xyxy2xywh, xywh2xyxy, clip_coords, increment_path, strip_optimizer, colorstr, check_file)
3636
from yolov7.utils.torch_utils import select_device, time_synchronized
3737
from yolov7.utils.plots import plot_one_box
3838
from strong_sort.utils.parser import get_config
3939
from strong_sort.strong_sort import StrongSORT
4040

4141

42+
# method from [https://github.com/WongKinYiu/yolov7/blob/u5/utils/plots.py#L474] for availabling '--save-crop' argument
43+
def save_one_box(xyxy, im, file=Path('im.jpg'), gain=1.02, pad=10, square=False, BGR=False, save=True):
44+
# Save image crop as {file} with crop size multiple {gain} and {pad} pixels. Save and/or return crop
45+
xyxy = torch.tensor(xyxy).view(-1, 4)
46+
b = xyxy2xywh(xyxy) # boxes
47+
if square:
48+
b[:, 2:] = b[:, 2:].max(1)[0].unsqueeze(1) # attempt rectangle to square
49+
b[:, 2:] = b[:, 2:] * gain + pad # box wh * gain + pad
50+
xyxy = xywh2xyxy(b).long()
51+
clip_coords(xyxy, im.shape)
52+
crop = im[int(xyxy[0, 1]):int(xyxy[0, 3]), int(xyxy[0, 0]):int(xyxy[0, 2]), ::(1 if BGR else -1)]
53+
if save:
54+
file.parent.mkdir(parents=True, exist_ok=True) # make directory
55+
f = str(Path(increment_path(file)).with_suffix('.jpg'))
56+
# cv2.imwrite(f, crop) # https://github.com/ultralytics/yolov5/issues/7007 chroma subsampling issue
57+
Image.fromarray(cv2.cvtColor(crop, cv2.COLOR_BGR2RGB)).save(f, quality=95, subsampling=0)
58+
return crop
59+
4260
VID_FORMATS = 'asf', 'avi', 'gif', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'ts', 'wmv' # include video suffixes
4361

4462

0 commit comments

Comments
 (0)