Exemple #1
0
    def evaluate_unit(self, data_dict):
        """
        Single evaluation unit. Given two sets of points and an estimated Fundamental matrix
        return the Epipolar-Constraint Errors

        :param pts1: points to run from img1
        :type pts1: array
        :param pts2: points to run from img2
        :type pts2: array
        :param task: What to run
        :type task: dict

        See Also
        --------
        evaluate_warpper: How to run the unit.
        dset.dataset.Link: definition of task.

        """
        est_F = data_dict['est_F']
        pts1 = data_dict['px_coords1']
        pts2 = data_dict['px_coords1']

        if est_F is None:
            est_F = geom.get_F_matrix_from_E(data_dict['est_E'],
                                             data_dict['K1'], data_dict['K2'])

        inlier_pts1, inlier_pts2, mask = geom.get_inliers_F(pts1, pts2, est_F)

        epiConst = geom.get_epi_constraint(inlier_pts1, inlier_pts2, est_F)
        epiAbs = np.sum(np.abs(epiConst))
        epiSqr = np.sum(epiConst**2)

        return epiAbs, epiSqr
Exemple #2
0
    def evaluate_unit(self, data_dict):
        """
        Single evaluation unit. Given two sets of points and an estimated Fundamental matrix
        return the Epipolar-Constraint Errors

        :param pts1: points to run from img1
        :type pts1: array
        :param pts2: points to run from img2
        :type pts2: array
        :param task: What to run
        :type task: dict

        See Also
        --------
        evaluate_warpper: How to run the unit.
        dset.dataset.Link: definition of task.

        """
        est_F = data_dict['est_F']
        pts1 = data_dict['px_coords1']
        pts2 = data_dict['px_coords2']

        if est_F is None:
            est_F = geom.get_F_matrix_from_E(data_dict['est_E'],
                                             data_dict['K1'], data_dict['K2'])
        est_F = data_dict['est_F']
        true_F = data_dict['F']
        pts1 = data_dict['px_coords1']
        pts2 = data_dict['px_coords2']
        true_inliers = data_dict['inlier_mask']

        if est_F is None:
            est_F = geom.get_F_matrix_from_E(data_dict['est_E'],
                                             data_dict['K1'], data_dict['K2'])

        #Run Processes

        #Get Inliers from estimated Fundamental Matrix
        inlier_pts1, inlier_pts2, inlier_mask = geom.get_inliers_F(
            pts1, pts2, est_F, dist_type='symmetric')

        #Epipolar Distance
        epiDists = geom.get_epidist(pts1, pts2, est_F, type='symmetric')
        mean_d = np.mean(epiDists[true_inliers.astype(bool)])
        median_d = np.median(epiDists[true_inliers.astype(bool)])
        if mean_d < 20:
            print(mean_d)

        return mean_d, median_d
Exemple #3
0
    def evaluate_unit(self, data_dict):
        """
        Single evaluation unit. Given two sets of points and an estimated Fundamental matrix
        return the Epipolar-Constraint Errors

        :param pts1: points to run from img1
        :type pts1: array
        :param pts2: points to run from img2
        :type pts2: array
        :param task: What to run
        :type task: dict

        See Also
        --------

        evaluate_warpper: How to run the unit.
        dset.dataset.Link: definition of task.

        """
        est_F = data_dict['est_F']
        pts1 = data_dict['px_coords1']
        pts2 = data_dict['px_coords1']

        if est_F is None:
            est_F = geom.get_F_matrix_from_E(data_dict['est_E'],
                                             data_dict['K1'], data_dict['K2'])

        true_inliers = data_dict['inlier_mask']
        inlier_pts1, _, inlier_mask = geom.get_inliers_F(pts1, pts2, est_F)

        prec, recall = geom.get_pr_recall(true_inliers=true_inliers,
                                          est_inliers=inlier_mask)

        num_inliers = len(inlier_pts1)
        inlierPerc = float(num_inliers) / len(pts1)

        return num_inliers, inlierPerc, prec, recall
Exemple #4
0
    def _prepare_data(self):
        """
        Prepares/calculates data from original data. Calculates Essential Matrix (E),
        Fundamental Matrix (F), pixel coordinates, and inlier correspondence pairs.
        """
        for seq in self.sequences:
            d = self.data[seq]

            #define new values
            norm_coords1, norm_coords2 = list(), list()
            px_coords1, px_coords2 = list(), list()
            cam_centers1, cam_centers2 = list(),  list()
            K1s, K2s = list(), list()
            Es, Fs = list(), list()
            inlier_mask = list()

            for idx in range(len(d['xs'])):
                pt1s = d['xs'][idx][0,:,:2]
                pt2s = d['xs'][idx][0,:,2:]
                cam_center1 = np.vstack((d['cx1s'], d['cy1s'])).T[idx]
                cam_center2 = np.vstack((d['cx2s'], d['cy2s'])).T[idx]
                norm_coords1.append(pt1s)
                norm_coords2.append(pt2s)
                cam_centers1.append(cam_center1)
                cam_centers2.append(cam_center2)

                f1 = d['f1s'][idx]
                f2 = d['f2s'][idx]
                K1 = d['k1s'][idx]
                K2 = d['k2s'][idx]
                img1 = d['img1s'][idx]
                img2 = d['img2s'][idx]

                #offset for principal point (origin at top left corner)
                K1[:,2] = np.array([img1.shape[2]/2.0, img1.shape[1]/2.0, 1.0])
                K2[:,2] = np.array([img2.shape[2]/2.0, img2.shape[1]/2.0, 1.0])

                K1s.append(K1)
                K2s.append(K2)

                px1 = to_pixel_coords(K1,pt1s)
                px2 = to_pixel_coords(K2,pt2s)

                px_coords1.append(px1)
                px_coords2.append(px2)

                R = d['Rs'][idx]
                t = d['ts'][idx]
                F = get_F_matrix(R, t, K1, K2)

                _, _, mask = get_inliers_F(px1, px2, F, thresh=1)
                inlier_mask.append(mask)
                Es.append(get_E_matrix(R, t))
                Fs.append(F)

            self.data[seq]['inlier_mask'] = inlier_mask
            self.data[seq]['norm_coords1'] = norm_coords1
            self.data[seq]['norm_coords2'] = norm_coords2

            self.data[seq]['px_coords1'] = px_coords1
            self.data[seq]['px_coords2'] = px_coords2
            self.data[seq]['K1s'] = K1s
            self.data[seq]['K2s'] = K2s
            self.data[seq]['Es'] = Es
            self.data[seq]['Fs'] = Fs
Exemple #5
0
    def evaluate_unit(self, data_dict):
        """
        Single evaluation unit. Given a dictionary of correspondence informatino between
        an image pair, run each verification on the image pair

        :param data_dict: Dictionary of data for an image pair.
        :type data_dict: dict

        **Structure of the data_dict:**
        data_dict['norm_coords1']: List of normalized coordinates for
                                    img1 of correspondence pair

        data_dict['norm_coords2']: List of normalized coordinates for
                                    img2 of correspondence pair

        data_dict['px_coords1']: List of pixel coordinates for
                                    img1 of correspondence pair

        data_dict['px_coords2']: List of pixel coordinates for
                                    img2 of correspondence pair

        data_dict['K1']:  3x3 np.array; Camera calibration matrix of cam from img1

        data_dict['K2']:  3x3 np.array; Camera calibration matrix of cam from img2

        data_dict['E']:  3x3 np.array; Ground-truth Essential Matrix from img1 to img2

        data_dict['F']:  3x3 np.array; Ground-truth Fundamental Matrix from img1 to img2

        data_dict['inlier_mask']: Nx1 np.array; Binary array indicating true correspondences

        --------

        evaluate_warpper: How to run the unit.
        dset.dataset.Link: definition of task.

        """
        est_F = data_dict['est_F']
        true_F = data_dict['F']
        pts1 = data_dict['px_coords1']
        pts2 = data_dict['px_coords1']

        if est_F is None:
            est_F = geom.get_F_matrix_from_E(data_dict['est_E'],
                                             data_dict['K1'],
                                             data_dict['K2'])

        #Run Processes

        #Get Inliers from estimated Fundamental Matrix
        inlier_pts1, inlier_pts2, inlier_mask  = geom.get_inliers_F(pts1, pts2, est_F, dist_type='symmetric')

        #Epipolar Distance
        epiDists = geom.get_epidist(pts1, pts2, est_F, type='symmetric')

        #Frobenius Norm Distance
        frobNorm = np.linalg.norm(true_F - est_F)

        #MEAN-D and MEDIAN-D
        mean_d = np.mean(epiDists)
        median_d = np.median(epiDists)

        #Precision and Recall
        true_inliers = data_dict['inlier_mask']
        prec, recall = geom.get_pr_recall(true_inliers=true_inliers, est_inliers=inlier_mask)

        #Inlier Percentage
        num_inliers = len(inlier_pts1)
        inlierPerc = float(num_inliers)/len(pts1)

        #Epipolar Constraint Metric
        epiConst = geom.get_epi_constraint(inlier_pts1, inlier_pts2, est_F)
        epiAbs = np.sum(np.abs(epiConst))
        epiSqr = np.sum(epiConst**2)


        return mean_d, median_d, num_inliers, inlierPerc, prec, recall, epiAbs, epiSqr, frobNorm