车位角点检测代码
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.

85 line
3.0KB

  1. """Collect the value range of different propertity of ps dataset."""
  2. import argparse
  3. import json
  4. import math
  5. import os
  6. import matplotlib.pyplot as plt
  7. import numpy as np
  8. from data import MarkingPoint
  9. from data.struct import calc_point_squre_dist, direction_diff
  10. from prepare_dataset import generalize_marks
  11. def get_parser():
  12. """Return argument parser for collecting thresholds."""
  13. parser = argparse.ArgumentParser()
  14. parser.add_argument('--label_directory', required=True,
  15. help="The location of label directory.")
  16. return parser
  17. def collect_thresholds(args):
  18. """Collect range of value from ground truth to determine threshold."""
  19. distances = []
  20. separator_angles = []
  21. bridge_angles = []
  22. for label_file in os.listdir(args.label_directory):
  23. print(label_file)
  24. with open(os.path.join(args.label_directory, label_file), 'r') as file:
  25. label = json.load(file)
  26. marks = np.array(label['marks'])
  27. slots = np.array(label['slots'])
  28. if slots.size == 0:
  29. continue
  30. if len(marks.shape) < 2:
  31. marks = np.expand_dims(marks, axis=0)
  32. if len(slots.shape) < 2:
  33. slots = np.expand_dims(slots, axis=0)
  34. marks[:, 0:4] -= 300.5
  35. marks = [MarkingPoint(*mark) for mark in generalize_marks(marks)]
  36. for slot in slots:
  37. mark_a = marks[slot[0] - 1]
  38. mark_b = marks[slot[1] - 1]
  39. distances.append(calc_point_squre_dist(mark_a, mark_b))
  40. vector_ab = np.array([mark_b.x - mark_a.x, mark_b.y - mark_a.y])
  41. vector_ab = vector_ab / np.linalg.norm(vector_ab)
  42. ab_bridge_direction = math.atan2(vector_ab[1], vector_ab[0])
  43. ba_bridge_direction = math.atan2(-vector_ab[1], -vector_ab[0])
  44. separator_direction = math.atan2(-vector_ab[0], vector_ab[1])
  45. sangle = direction_diff(separator_direction, mark_a.direction)
  46. if mark_a.shape > 0.5:
  47. separator_angles.append(sangle)
  48. else:
  49. bangle = direction_diff(ab_bridge_direction, mark_a.direction)
  50. if sangle < bangle:
  51. separator_angles.append(sangle)
  52. else:
  53. bridge_angles.append(bangle)
  54. bangle = direction_diff(ba_bridge_direction, mark_b.direction)
  55. if mark_b.shape > 0.5:
  56. bridge_angles.append(bangle)
  57. else:
  58. sangle = direction_diff(separator_direction, mark_b.direction)
  59. if sangle < bangle:
  60. separator_angles.append(sangle)
  61. else:
  62. bridge_angles.append(bangle)
  63. distances = sorted(distances)
  64. separator_angles = sorted(separator_angles)
  65. bridge_angles = sorted(bridge_angles)
  66. plt.figure()
  67. plt.hist(distances, len(distances) // 10)
  68. plt.figure()
  69. plt.hist(separator_angles, len(separator_angles) // 10)
  70. plt.figure()
  71. plt.hist(bridge_angles, len(bridge_angles) // 3)
  72. if __name__ == '__main__':
  73. collect_thresholds(get_parser().parse_args())