Ejemplo n.º 1
0
def select_corner_knees(points: np.ndarray,
                        knees: np.ndarray,
                        t: float = .33) -> np.ndarray:
    """
    Detect and keep the left upper corner knees points.

    The detection method relies on a three point rectangle fitting and overlap.

    Args:
        points (np.ndarray): numpy array with the points (x, y)
        knees (np.ndarray): knees indexes
        t (float): overlap treshold (default 0.33)

    Returns:
        np.ndarray: the filtered knees
    """

    filtered_knees = []

    for i in range(len(knees)):
        idx = knees[i]
        if idx - 1 >= 0 and idx + 1 < len(points):
            p0, p1, p2 = points[idx - 1:idx + 2]
            corner0 = np.array([p0[0], p2[1]])
            amin, amax = kr.rect(corner0, p1)
            bmin, bmax = kr.rect(p0, p2)
            p = kr.rect_overlap(amin, amax, bmin, bmax)

            if p >= t:
                filtered_knees.append(idx)

    return np.array(filtered_knees)
Ejemplo n.º 2
0
 def test_rect_overlap(self):
     amin = np.array([2, 1])
     amax = np.array([5, 5])
     bmin = np.array([3, 2])
     bmax = np.array([5, 7])
     result = ranking.rect_overlap(amin, amax, bmin, bmax)
     desired = 0.375
     self.assertEqual(result, desired)
Ejemplo n.º 3
0
 def test_lower_overlap_02(self):
     points = np.array([[0,1],[1,0],[2,1]])
     idx = 1
     p0, p1, p2 = points[idx-1:idx+2]
     corner0 = np.array([p2[0], p0[1]])
     amin, amax = ranking.rect(corner0, p1)
     bmin, bmax = ranking.rect(p0, p2)
     result = ranking.rect_overlap(amin, amax, bmin, bmax)
     desired = 0.0
     self.assertEqual(result, desired)
Ejemplo n.º 4
0
 def test_lower_overlap_03(self):
     amin, amax = (np.array([782, 3.47059833e-01]), np.array([805, 3.49430416e-01]))
     bmin, bmax = (np.array([759, 3.48911963e-01]), np.array([805, 3.49430416e-01]))
     result = ranking.rect_overlap(amin, amax, bmin, bmax)
     desired = 0.17945536158082412
     self.assertEqual(result, desired)