Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yolov7 #16

Merged
merged 5 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/StrongSORT-YOLO/.DS_Store
Binary file not shown.
388 changes: 388 additions & 0 deletions src/StrongSORT-YOLO/track_v7.py

Large diffs are not rendered by default.

69 changes: 42 additions & 27 deletions src/StrongSORT-YOLO/tracker.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
from pathlib import Path
import track_v7
import sys
import os
import track_v5
import pickle
import multiprocessing as mp
import threading as th
import time

FILE = Path(__file__).resolve()
ROOT = FILE.parents[0] # yolov5 strongsort root directory
WEIGHTS = ROOT / 'weights'

def track_person(res, source_mov:str, idx:int):
""" tracks persons in video and puts data in out_queue"""
out_array_pr, vid_path = track_v5.run(source = source_mov, classes= [1, 2], yolo_weights =
WEIGHTS / 'best.pt', save_vid=False, ret=True)

ROOT = FILE.parents[0]
WEIGHTS = ROOT / "weights"


def track_person(res, source_mov: str, idx: int):
"""tracks persons in video and puts data in out_queue"""
out_array_pr, vid_path = track_v7.run(
source=source_mov,
classes=[1, 2],
yolo_weights=WEIGHTS / "best.pt",
save_vid=False,
ret=True,
)

res[idx] = (out_array_pr, vid_path)

print("==============Put data from tracking person and rim============")
return

def track_basketball(res, source_mov:str, idx:int):
""" tracks basketball in video and puts data in out_queue"""
out_array_bb, bb_vid_path = track_v5.run(source = source_mov,
yolo_weights = WEIGHTS / 'best_basketball.pt',
save_vid=False, ret=True, skip_big=True)


def track_basketball(res, source_mov: str, idx: int):
"""tracks basketball in video and puts data in out_queue"""
out_array_bb, bb_vid_path = track_v7.run(
source=source_mov,
yolo_weights=WEIGHTS / "best_basketball.pt",
save_vid=False,
ret=True,
skip_big=True,
)

res[idx] = (out_array_bb, bb_vid_path)

print("==============Put data from tracking basketball============")
return

def get_data(source_mov:str):
""" returns dict as: {

def get_data(source_mov: str):
"""returns dict as: {
'basketball_data': (basketball_bounding_boxes, video_path),
'person_data': (persons_and_rim_bounding_boxes, vide_path)
}.
Expand All @@ -42,7 +54,6 @@ def get_data(source_mov:str):
source_mov (string path): path to video file
"""


# ---------THREADING APPROACH---------------

# res = [None] * 2
Expand Down Expand Up @@ -81,16 +92,20 @@ def get_data(source_mov:str):

end = time.time()

print(f'=============time elapsed: {end-start}=================')

return {'basketball_data': (out_array_bb, bb_vid_path), 'person_data': (out_array_pr, vid_path)}
print(f"=============time elapsed: {end-start}=================")

return {
"basketball_data": (out_array_bb, bb_vid_path),
"person_data": (out_array_pr, vid_path),
}


if __name__ == '__main__':
video_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', sys.argv[1])
if __name__ == "__main__":
video_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "..", "..", sys.argv[1]
)
output = get_data(video_path)
print(output['basketball_data'])
print('MODEL RUN DONE')
with open('../../tmp/test_output.pickle', 'wb') as f:
print(output["basketball_data"])
print("MODEL RUN DONE")
with open("../../tmp/test_output.pickle", "wb") as f:
pickle.dump(output, f)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/StrongSORT-YOLO/yolov7/figure/mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/StrongSORT-YOLO/yolov7/figure/pose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/StrongSORT-YOLO/yolov7/figure/tennis.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/processing/court.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def _max_pixel_overlap(self, im_src: np.ndarray, pts_src: list, pts_dst=None):
"""
all_white = np.full_like(im_src, 255)
max_overlap = self._apply_gray_homography(all_white, pts_src, pts_dst=pts_dst)
return np.count_nonzero(max_overlap > 100)
return np.count_nonzero(max_overlap > 100) + 1

def _apply_bgr_homography(self, im_src: np.ndarray, pts_src: list):
"""
Expand Down