落水人员检测
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.1KB

  1. import numpy as np
  2. def center_coordinate(boundbxs):
  3. '''
  4. 输入:两个对角坐标xyxy
  5. 输出:矩形框重点坐标xy
  6. '''
  7. boundbxs_x1=boundbxs[0]
  8. boundbxs_y1=boundbxs[1]
  9. boundbxs_x2=boundbxs[2]
  10. boundbxs_y2=boundbxs[3]
  11. center_x=0.5*(boundbxs_x1+boundbxs_x2)
  12. center_y=0.5*(boundbxs_y1+boundbxs_y2)
  13. return center_x,center_y
  14. def fourcorner_coordinate(boundbxs):
  15. '''
  16. 输入:两个对角坐标xyxy
  17. 输出:矩形框四个角点坐标,以contours顺序。
  18. '''
  19. boundbxs_x1=boundbxs[0]
  20. boundbxs_y1=boundbxs[1]
  21. boundbxs_x2=boundbxs[2]
  22. boundbxs_y2=boundbxs[3]
  23. wid=boundbxs_x2-boundbxs_x1
  24. hei=boundbxs_y2-boundbxs_y1
  25. boundbxs_x3=boundbxs_x1+wid
  26. boundbxs_y3=boundbxs_y1
  27. boundbxs_x4=boundbxs_x1
  28. boundbxs_y4 = boundbxs_y1+hei
  29. contours_rec=[[boundbxs_x1,boundbxs_y1],[boundbxs_x3,boundbxs_y3],[boundbxs_x2,boundbxs_y2],[boundbxs_x4,boundbxs_y4]]
  30. return contours_rec
  31. def remove_simivalue(list1,list2):
  32. '''
  33. 将list1中属于list2的元素都删除。
  34. 输入:两个嵌套列表
  35. 返回:嵌套列表
  36. '''
  37. list33=list1.copy()
  38. for i in range(len(list1)):
  39. for j in range(len(list2)):
  40. if list2[j] == list1[i]:
  41. # list33.pop(list1[i])
  42. list33.remove(list1[i])
  43. return list33
  44. def remove_sameeleme_inalist(list3):
  45. '''
  46. 将list3中重复嵌套列表元素删除。
  47. 输入:嵌套列表
  48. 返回:嵌套列表
  49. '''
  50. list3=list3
  51. list4=[]
  52. list4.append(list3[0])
  53. for dict in list3:
  54. k=0
  55. for item in list4:
  56. if dict!=item:
  57. k=k+1
  58. else:
  59. break
  60. if k==len(list4):
  61. list4.append(dict)
  62. return list4
  63. def order_points(pts):
  64. ''' sort rectangle points by clockwise '''
  65. sort_x = pts[np.argsort(pts[:, 0]), :]
  66. Left = sort_x[:2, :]
  67. Right = sort_x[2:, :]
  68. # Left sort
  69. Left = Left[np.argsort(Left[:, 1])[::-1], :]
  70. # Right sort
  71. Right = Right[np.argsort(Right[:, 1]), :]
  72. return np.concatenate((Left, Right), axis=0)