Akjava's picture
add
0aba763
raw
history blame
925 Bytes
# DrawUtils
# not PIL,CV2,Numpy drawing method
import math
# 2024-11-29 add calculate_distance
def points_to_box(points):
x1=float('inf')
x2=0
y1=float('inf')
y2=0
for point in points:
if point[0]<x1:
x1=point[0]
if point[0]>x2:
x2=point[0]
if point[1]<y1:
y1=point[1]
if point[1]>y2:
y2=point[1]
return [x1,y1,x2-x1,y2-y1]
def box_to_point(box):
return [
[box[0],box[1]],
[box[0]+box[2],box[1]],
[box[0]+box[2],box[1]+box[3]],
[box[0],box[1]+box[3]]
]
def plus_point(base_pt,add_pt):
return [base_pt[0]+add_pt[0],base_pt[1]+add_pt[1]]
def box_to_xy(box):
return [box[0],box[1],box[2]+box[0],box[3]+box[1]]
def to_int_points(points):
int_points=[]
for point in points:
int_points.append([int(point[0]),int(point[1])])
return int_points
def calculate_distance(xy, xy2):
return math.sqrt((xy2[0] - xy[0])**2 + (xy2[1] - xy[1])**2)