Skip to content

Commit

Permalink
Added demo2
Browse files Browse the repository at this point in the history
  • Loading branch information
cris committed Apr 12, 2021
1 parent cda9824 commit ccb3615
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# BasketTracking

We aim at developing a system capable of
action tracking and understanding in basketball games using
different computer vision approaches and ideas alongside
deep learning models such as Detectron2.
We aim at developing a system capable of action tracking and understanding in basketball games using different computer
vision approaches and ideas alongside deep learning models such as Detectron2.

### Demo

<p align='center'>
<img src="demo.gif" width="90%"/>
</p>


### Demo
<p align='center'>
<img src="demo.gif" />
<img src="demo2.gif" width="90%"/>
</p>

8 changes: 4 additions & 4 deletions ball_detect_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ def ball_tracker(self, M, M1, frame, map_2d, map_2d_text, timestamp):
ball_center = np.array([int(bbox[0] + bbox[2] / 2), int(bbox[1] + bbox[3] / 2), 1])
clean_frame = frame.copy()

bbox_iou = (ball_center[1]-IOU_BALL_PADDING,
ball_center[0]- IOU_BALL_PADDING,
ball_center[1]+IOU_BALL_PADDING,
ball_center[0]+IOU_BALL_PADDING)
bbox_iou = (ball_center[1] - IOU_BALL_PADDING,
ball_center[0] - IOU_BALL_PADDING,
ball_center[1] + IOU_BALL_PADDING,
ball_center[0] + IOU_BALL_PADDING)
scores = []

for p in self.players:
Expand Down
4 changes: 2 additions & 2 deletions feet_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def bb_intersection_over_union(boxA, boxB):
# return the intersection over union value
return iou


def get_players_pos(self, M, M1, frame, timestamp, map_2d):
warped_kpts = []
outputs_seg = self.predictor_seg(frame)
Expand All @@ -86,7 +85,8 @@ def get_players_pos(self, M, M1, frame, timestamp, map_2d):

for i, entry in enumerate(indices): # picking only class 0 (people)
if entry == 0:
ppl.append(np.array(cv2.erode(np.array(predicted_masks[i], dtype=np.uint8), kernel, iterations=4), dtype=bool))
ppl.append(
np.array(cv2.erode(np.array(predicted_masks[i], dtype=np.uint8), kernel, iterations=4), dtype=bool))

indexes_ppl = np.array(
[np.array(np.where(p == True)).T for p in ppl])
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get_frames(video_path, central_frame, mod):
resized = cv2.resize(rectified, (map.shape[1], map.shape[0]))
map = cv2.resize(map, (rectified.shape[1], rectified.shape[0]))

video = cv2.VideoCapture("resources/Short4Mosaicing.mp4")
video = cv2.VideoCapture("resources/Short4Mosaicing2.mp4")

players = []
for i in range(1, 6):
Expand Down
5 changes: 3 additions & 2 deletions video_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, pano, video, ball_detector, feet_detector, map_2d):
self.map_2d = map_2d

def run_detectors(self):
writer = skvideo.io.FFmpegWriter("demo.mp4")
writer = skvideo.io.FFmpegWriter("demo2.mp4")
time_index = 0
while self.video.isOpened():
ok, frame = self.video.read()
Expand All @@ -39,7 +39,8 @@ def run_detectors(self):
M = self.get_homography(frame, self.des1, self.kp1)
frame, self.map_2d, map_2d_text = self.feet_detector.get_players_pos(M, self.M1, frame, time_index,
self.map_2d)
frame, ball_map_2d = self.ball_detector.ball_tracker(M, self.M1, frame, self.map_2d.copy(), map_2d_text, time_index)
frame, ball_map_2d = self.ball_detector.ball_tracker(M, self.M1, frame, self.map_2d.copy(),
map_2d_text, time_index)
vis = np.vstack((frame, cv2.resize(map_2d_text, (frame.shape[1], frame.shape[1] // 2))))

cv2.imshow("Tracking", vis)
Expand Down

0 comments on commit ccb3615

Please sign in to comment.