def test_point_distance(self): l1 = Line((0, 0), (0, 1)) point1 = (0, 0) point2 = (1, 0) self.assertEqual(l1.point_distance(point1), 0) self.assertEqual(l1.point_distance(point2), 1)
def find_stop_line(self): """ Finds stop line from stored stop-points. For stop line is used second vanishing point which is used as anchor for all detected stop line points. Stop line is detected using RANSAC algorithm. """ best_line_ratio = 0 best_line = None vp2 = self._info.vanishing_points[1] test_image = np.zeros(shape=(self._info.height, self._info.width)) for point in self._stop_places: cv2.circle(test_image, point.tuple(), radius=5, color=255, thickness=5) cv2.imwrite("stopky.png", test_image) for point2 in self._stop_places: try: line = Line(vp2.point, point2.tuple()) except SamePointError: continue except VanishingPointError: line = Line(point1=point2.tuple(), direction=vp2.direction) num = 0 ransac_threshold = constants.CORRIDORS_RANSAC_THRESHOLD for point in self._stop_places: distance = line.point_distance(point.tuple()) if distance < ransac_threshold: num += 1 if num > best_line_ratio: best_line_ratio = num best_line = line self.stopline = best_line self._stopline_found = True