Drowning_Person_Detection/utils/postprocess_utils.py

79 lines
2.1 KiB
Python
Raw Permalink Normal View History

2023-12-27 14:52:39 +08:00
import numpy as np
def center_coordinate(boundbxs):
'''
输入两个对角坐标xyxy
输出矩形框重点坐标xy
'''
boundbxs_x1=boundbxs[0]
boundbxs_y1=boundbxs[1]
boundbxs_x2=boundbxs[2]
boundbxs_y2=boundbxs[3]
center_x=0.5*(boundbxs_x1+boundbxs_x2)
center_y=0.5*(boundbxs_y1+boundbxs_y2)
return center_x,center_y
def fourcorner_coordinate(boundbxs):
'''
输入两个对角坐标xyxy
输出矩形框四个角点坐标以contours顺序
'''
boundbxs_x1=boundbxs[0]
boundbxs_y1=boundbxs[1]
boundbxs_x2=boundbxs[2]
boundbxs_y2=boundbxs[3]
wid=boundbxs_x2-boundbxs_x1
hei=boundbxs_y2-boundbxs_y1
boundbxs_x3=boundbxs_x1+wid
boundbxs_y3=boundbxs_y1
boundbxs_x4=boundbxs_x1
boundbxs_y4 = boundbxs_y1+hei
contours_rec=[[boundbxs_x1,boundbxs_y1],[boundbxs_x3,boundbxs_y3],[boundbxs_x2,boundbxs_y2],[boundbxs_x4,boundbxs_y4]]
return contours_rec
def remove_simivalue(list1,list2):
'''
将list1中属于list2的元素都删除
输入两个嵌套列表
返回嵌套列表
'''
list33=list1.copy()
for i in range(len(list1)):
for j in range(len(list2)):
if list2[j] == list1[i]:
# list33.pop(list1[i])
list33.remove(list1[i])
return list33
def remove_sameeleme_inalist(list3):
'''
将list3中重复嵌套列表元素删除
输入嵌套列表
返回嵌套列表
'''
list3=list3
list4=[]
list4.append(list3[0])
for dict in list3:
k=0
for item in list4:
if dict!=item:
k=k+1
else:
break
if k==len(list4):
list4.append(dict)
return list4
def order_points(pts):
''' sort rectangle points by clockwise '''
sort_x = pts[np.argsort(pts[:, 0]), :]
Left = sort_x[:2, :]
Right = sort_x[2:, :]
# Left sort
Left = Left[np.argsort(Left[:, 1])[::-1], :]
# Right sort
Right = Right[np.argsort(Right[:, 1]), :]
return np.concatenate((Left, Right), axis=0)