Football-Analysis / utils /bbx_utils.py
Alhasan-mahmood's picture
Upload 61 files
70e526c verified
raw
history blame contribute delete
840 Bytes
def get_center_of_bbox(bbox): # calculates the center point of a bounding box
x1, y1, x2, y2 = bbox
return int((x1+x2)/2), int((y1+y2)/2)
def get_bbox_width(bbox): # calculates the width of a bounding box
x1, y1, x2, y2 = bbox
return x2-x1
# calculates the Euclidean distance between two points in a 2D space.
def measure_distance(point1, point2):
x1, y1 = point1
x2, y2 = point2
return ((x1-x2)**2+(y1-y2)**2)**0.5
# calculates the horizontal and vertical distance between two points in a 2D space
def measure_xy_distance(point1, point2):
x1, y1 = point1
x2, y2 = point2
return (abs(x1-x2), abs(y1-y2))
# calculates the foot position of an object based on its bounding box.
def get_foot_position(bbox):
x1, y1, x2, y2 = bbox
return (int((x1+x2)/2), y2)