def test_point_line_distance(self):
        """
        Testing point line distance calculation
        """
        line = [3, 4, 6]
        point = [2, 1, 1]
        distance = 16.0/5

        test_distance = point_line_distance(line, point)
        self.assertEqual(distance, test_distance)
示例#2
0
def find_inliers(x_0s, F, x_1s, threshold):
    """ Find the inliers' indices for a given model.

    There are multiple methods you could use for calculating the error
    to determine your inliers vs outliers at each pass. CoHowever, we suggest
    using the line to point distance function we wrote for the
    optimization in part 2.

    Args:
    -   x_0s: A numpy array of shape (N, 2) representing the coordinates
                   of possibly matching points from the left image
    -   F: The proposed fundamental matrix
    -   x_1s: A numpy array of shape (N, 2) representing the coordinates
                   of possibly matching points from the right image
    -   threshold: the maximum error for a point correspondence to be
                    considered an inlier
    Each row in x_1s and x_0s is a proposed correspondence (e.g. row #42 of x_0s is a point that
    corresponds to row #42 of x_1s)

    Returns:
    -    inliers: 1D array of the indices of the inliers in x_0s and x_1s

    """
    inliers = []
    for i in range(x_0s.shape[0]):
        x0 = x_0s[i]
        x1 = x_1s[i]
        line0 = np.dot(F, x1)
        dist0 = fundamental_matrix.point_line_distance(line0, x0)

        line1 = np.dot(np.transpose(F), x0)
        dist1 = fundamental_matrix.point_line_distance(line1, x1)

        if np.abs(dist0) <= threshold and np.abs(dist1) <= threshold:
            inliers.append(i)

    return np.array(inliers)
示例#3
0
def find_inliers(x_0s, F, x_1s, threshold):
    """ Find the inliers' indices for a given model.

    There are multiple methods you could use for calculating the error
    to determine your inliers vs outliers at each pass. CoHowever, we suggest
    using the line to point distance function we wrote for the
    optimization in part 2.

    Args:
    -   x_0s: A numpy array of shape (N, 2) representing the coordinates
                   of possibly matching points from the left image
    -   F: The proposed fundamental matrix
    -   x_1s: A numpy array of shape (N, 2) representing the coordinates
                   of possibly matching points from the right image
    -   threshold: the maximum error for a point correspondence to be
                    considered an inlier
    Each row in x_1s and x_0s is a proposed correspondence (e.g. row #42 of x_0s is a point that
    corresponds to row #42 of x_1s)

    Returns:
    -    inliers: 1D array of the indices of the inliers in x_0s and x_1s

    """
    ##############################
    # TODO: Student code goes here
    inliers = []
    for idx in range(len(x_1s)):
        line = np.matmul(F, x_1s[idx])
        line_T = np.matmul(F.transpose(), x_0s[idx])
        dist = fundamental_matrix.point_line_distance(line, x_0s[idx])
        dist2 = fundamental_matrix.point_line_distance(line_T, x_1s[idx])
        if (abs(dist) + abs(dist2) < 2 * threshold): inliers.append(idx)

    ##############################

    return np.array(inliers)
示例#4
0
def find_inliers(x_0s, F, x_1s, threshold):
    """ Find the inliers' indices for a given model.

    There are multiple methods you could use for calculating the error
    to determine your inliers vs outliers at each pass. However, we suggest
    using the line to point distance function we wrote for the
    optimization in part 2.

    Args:
    -   x_0s: A numpy array of shape (N, 2) representing the coordinates
                   of possibly matching points from the left image
    -   F: The proposed fundamental matrix
    -   x_1s: A numpy array of shape (N, 2) representing the coordinates
                   of possibly matching points from the right image
    -   threshold: the maximum error for a point correspondence to be
                    considered an inlier
    Each row in x_1s and x_0s is a proposed correspondence (e.g. row #42 of x_0s is a point that
    corresponds to row #42 of x_1s)

    Returns:
    -    inliers: list of the indices of the inliers in x_0s and x_1s

    """
    ##############################
    # TODO: Student code goes here

    inliers = []
    for x in range(len(x_0s)):
        p1 = x_1s[x]
        p2 = x_0s[x]
        if len(p1) < 3:
            p1 = np.append(p1, 1)
            p2 = np.append(p2, 1)
        Fx1 = np.dot(F, p1)
        d = fundamental_matrix.point_line_distance(Fx1, p2)
        d = abs(d)
        if (d <= threshold):
            inliers.append(x)
    inliers = np.array(inliers)

    ##############################

    return inliers
    def test_point_line_distance_zero(self):
        line = [3, 3, -6]
        point = [1, 1, 1]

        test_distance = point_line_distance(line, point)
        self.assertEqual(test_distance, 0)