Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ozora-ogino committed Dec 10, 2021
1 parent 2cc16f0 commit 619d56f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion models/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
**.tflite
!.gitignore
!.gitignore
!yolov5n6-fp16.tflite
3 changes: 2 additions & 1 deletion src/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def preprocess(self, img: np.ndarray) -> np.ndarray:
img = np.expand_dims(img, axis=0)
return img.astype(np.float32)

def postprocess(self, output_data, box_type: str):
def postprocess(self, output_data, box_type: str) -> Tuple[np.ndarray]:
"""Postprocess."""
output_data = output_data[0]
# xywh
Expand All @@ -80,6 +80,7 @@ def postprocess(self, output_data, box_type: str):

def to_xyxy(self, boxes: np.ndarray) -> np.ndarray:
"""Covert xywh to xyxy."""
# (x, y) is cordinate fo the center of the box.
x, y, w, h = boxes[..., 0], boxes[..., 1], boxes[..., 2], boxes[..., 3]
boxes = np.array([x - w / 2, y - h / 2, x + w / 2, y + h / 2])
# [4, n] -> [n, 4]
Expand Down
1 change: 1 addition & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def main(
end = time.time()

# Update tracker and draw bounding boxes in frame.
# dets: [xmin, ymin, xmax, ymax, score]
frame = tracker.update(frame, dets)

# Executed only first time.
Expand Down
1 change: 0 additions & 1 deletion src/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def __init__(
self.border = border
self.count_callback = count_callback
self.memory = {}
self.counter = 0
self.counter = {key: 0 for key in directions.keys()}
self.directions = directions

Expand Down
3 changes: 2 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# Copyright 2021.
# ozora-ogino

from typing import List, Tuple

# Direction configuration.
Expand Down Expand Up @@ -36,7 +37,7 @@ def check_direction(
# True if the direction is right.
direction_x = (current_center[0] - prev_center[0]) > 0
# True if the direction is top.
direction_y = (current_center[1] - prev_center[1]) > 0
direction_y = (current_center[1] - prev_center[1]) < 0

x_is_true = direction[0] is None or direction_x is direction[0]
y_is_true = direction[1] is None or direction_y is direction[1]
Expand Down

0 comments on commit 619d56f

Please sign in to comment.