def test_ransac_circle_fit_on_two_points_returns_none(self): points = np.array( make_circular_vertices(radius=2, center=(2, 2), num_pts=2)) result = geom.ransac_circle_fit(points, desired_radius=2, consensus=0.99, tolerance=0.03, iterations=10) self.assertIsNone(result)
def test_ransac_circle_fit_on_linear_vertices_fails(self): points = np.array( make_linear_vertices(start=(2, 2), end=(5, 5), num_pts=8)) result = geom.ransac_circle_fit(points, desired_radius=2, consensus=0.99, tolerance=0.03, iterations=10) self.assertIsNone(result)
def test_ransac_circle_fit_on_circular_vertices_with_wrong_radius_fails( self): points = np.array( make_circular_vertices(radius=3, center=(2, 2), num_pts=8)) result = geom.ransac_circle_fit(points, desired_radius=2, consensus=0.99, tolerance=0.03, iterations=10) self.assertIsNone(result)
def classify(self, vehicle_state): """ Classifies each cluster of points as either ball or obstacle from vehicle_state['clusters'], which is an Nx2 array of points. The resulting balls are stored into vehicle_state['balls'] as a list of circles as ((x, y), radius) and the resulting obstacles are placed into vehicle_state['obstacles'] as a list of rectangles as ((min_x, min_y), (max_x, max_y)) """ clusters = vehicle_state['clusters'] balls = list() obstacles = list() for cluster in clusters: ball = geom.ransac_circle_fit(cluster, desired_radius=self.ball_radius, consensus=0.99, tolerance=0.03, iterations=10) if ball is not None: ball_pos, ball_radius = ball balls.append(ball_pos) else: # Construct a bounding box and put into obstacles list obstacles.append(geom.bounding_box(cluster)) vehicle_state['balls'] = balls vehicle_state['obstacles'] = obstacles
def test_ransac_circle_fit_on_circular_vertices_with_correct_radius_succeeds( self): points = np.array( make_circular_vertices(radius=2, center=(2, 2), num_pts=8)) result = geom.ransac_circle_fit(points, desired_radius=2, consensus=0.99, tolerance=0.03, iterations=10) expected = ((2, 2), 2) expected_center_x = expected[0][0] expected_center_y = expected[0][1] expected_radius = expected[1] actual = result actual_center_x = actual[0][0] actual_center_y = actual[0][1] actual_radius = actual[1] self.assertAlmostEqual(expected_center_x, actual_center_x) self.assertAlmostEqual(expected_center_y, actual_center_y) self.assertAlmostEqual(expected_radius, actual_radius)