Ejemplo n.º 1
0
    def test_chamfer(self):
        import point_cloud_utils as pcu
        import numpy as np

        # a and b are arrays where each row contains a point
        # Note that the point sets can have different sizes (e.g [100, 3], [111, 3])
        a = np.random.rand(100, 3)
        b = np.random.rand(100, 3)

        chamfer_dist = pcu.chamfer(a, b)
Ejemplo n.º 2
0
    def test_batched_chamfer(self):
        import point_cloud_utils as pcu
        import numpy as np

        # a and b are each contain 10 batches each of which contain 100 points  of dimension 3
        # i.e. a[i, :, :] is the i^th point set which contains 100 points
        # Note that the point sets can have different sizes (e.g [10, 100, 3], [10, 111, 3])
        a = np.random.rand(10, 100, 3)
        b = np.random.rand(10, 100, 3)

        chamfer_dist = pcu.chamfer(a, b)
Ejemplo n.º 3
0
    def full_evaluation(self, opt_solution_path, checkpoint_path, method):
        dataset = pd.read_csv(opt_solution_path, header=None, index_col=None)
        X = dataset.drop(dataset.columns[-1], axis=1).values
        Y = dataset[dataset.columns[-1]].values
        model = load(checkpoint_path)
        Y_ = model.predict(X)
        checker_flag = 0
        other_best_idx = []
        true_flag = int(np.sum(Y))
        all_sol_count = X.shape[0]
        cheb_all = np.zeros(all_sol_count)
        man_all = np.zeros(all_sol_count)
        euc_all = np.zeros(all_sol_count)

        chamfer = np.zeros(all_sol_count)

        angular = np.zeros(all_sol_count)

        idx_array = []

        res = np.sum(Y_[np.where(Y_ == Y)])

        if int(res) == 0:
            return False
        else:
            julia = Triangulation(K=self.K, R1=self.R1, R2=self.R2, T1=self.T1, T2=self.T2)
            julia.load_imgs(self.img1_path, self.img2_path)
            julia.findRootSIFTFeatures(n_components=self.n_components)

            for idx, item in enumerate(Y_):
                if Y[idx] == Y_[idx] and item == 1.0:
                    checker_flag+=1
                    idx_array.append(idx)
                else:
                    other_best_idx.append(idx)
                julia.matchingRootSIFTFeatures_advanced(X[idx])
                julia.findRTmatrices()
                julia.point_cloud(plot=self.draw_plot, title="Our method #{}".format(idx))
                pred = julia.pts3D

                stop = 1

                metrics_1 = Hausdorff(u=pred, v=self.target)
                metrics_2 = Hausdorff(u=self.target, v=pred)
                chamfer_dist = pcu.chamfer(pred, self.target)
                ang_sim = AngularSimilarity(pred, self.target)
                ang_dist = ang_sim.compute_distance()
                if method == 'avg':

                    dist_cheb_avg = np.add(metrics_1.distance(d_type="cheb", criteria="avg"),
                                     metrics_2.distance(d_type="cheb", criteria="avg"))/2
                    dist_man_avg = np.add(metrics_1.distance(d_type="man", criteria="avg"),
                                    metrics_2.distance(d_type="man", criteria="avg"))/2
                    dist_euc_avg = np.add(metrics_1.distance(d_type="euc", criteria="avg"),
                                    metrics_2.distance(d_type="euc", criteria="avg"))/2
                elif method == 'min':
                    dist_cheb_avg = min(metrics_1.distance(d_type="cheb", criteria="avg"),
                                     metrics_2.distance(d_type="cheb", criteria="avg"))
                    dist_man_avg = min(metrics_1.distance(d_type="man", criteria="avg"),
                                    metrics_2.distance(d_type="man", criteria="avg"))
                    dist_euc_avg = min(metrics_1.distance(d_type="euc", criteria="avg"),
                                    metrics_2.distance(d_type="euc", criteria="avg"))
                elif method == "max":
                    dist_cheb_avg = max(metrics_1.distance(d_type="cheb", criteria="avg"),
                                     metrics_2.distance(d_type="cheb", criteria="avg"))
                    dist_man_avg = max(metrics_1.distance(d_type="man", criteria="avg"),
                                    metrics_2.distance(d_type="man", criteria="avg"))
                    dist_euc_avg = max(metrics_1.distance(d_type="euc", criteria="avg"),
                                    metrics_2.distance(d_type="euc", criteria="avg"))
                else:
                    return False
                cheb_all[idx] = dist_cheb_avg
                man_all[idx] = dist_man_avg
                euc_all[idx] = dist_euc_avg
                chamfer[idx] = chamfer_dist

                angular[idx] = ang_dist

            min_chamfer_other = np.max(chamfer[other_best_idx])
            min_angular_other = np.max(angular[other_best_idx])


            min_cheb_other = np.max(cheb_all[other_best_idx])
            min_man_other  = np.max(man_all[other_best_idx])
            min_euc_other  = np.max(euc_all[other_best_idx])

            min_angular = np.max(angular[idx_array])
            min_chamfer = np.max(chamfer[idx_array])
            min_cheb = np.max(cheb_all[idx_array])
            min_man = np.max(man_all[idx_array])
            min_euc = np.max(euc_all[idx_array])

            print("\nPredicted : {} out of actual: {}".format(checker_flag, true_flag))
            # print("Other: Cheb: {:3f} Man: {:3f} Euc: {:3f}".format(min_cheb_other, min_man_other, min_euc_other))
            # print("Our:   Cheb: {:3f} Man: {:3f} Euc: {:3f}".format(min_cheb, min_man, min_euc))
            # print()

            print("Other: Chamfer: {:3f}".format(min_angular_other))
            print("Our:   Chamfer: {:3f}".format(min_angular))
            print()
            if min_angular < min_angular_other:
                return True
            else:
                return False