예제 #1
0
def main():
    # configuration
    db_size = 64000
    dim = 3
    leaf_size = 32
    min_extent = 0.0001
    k = 8
    radius = 1

    iteration_num = 100

    print("octree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    for i in range(iteration_num):
        db_np = (np.random.rand(db_size, dim) - 0.5) * 100

        begin_t = time.time()
        root = octree.octree_construction(db_np, leaf_size, min_extent)
        construction_time_sum += time.time() - begin_t

        query = np.random.rand(3)

        begin_t = time.time()
        result_set = KNNResultSet(capacity=k)
        octree.octree_knn_search(root, db_np, result_set, query)
        knn_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set = RadiusNNResultSet(radius=radius)
        octree.octree_radius_search_fast(root, db_np, result_set, query)
        radius_time_sum += time.time() - begin_t

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
    print("Octree: build %.3f, knn %.3f, radius %.3f, brute %.3f" %
          (construction_time_sum * 1000 / iteration_num, knn_time_sum * 1000 /
           iteration_num, radius_time_sum * 1000 / iteration_num,
           brute_time_sum * 1000 / iteration_num))

    print("kdtree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    for i in range(iteration_num):
        db_np = np.random.rand(db_size, dim)

        begin_t = time.time()
        root = kdtree.kdtree_construction(db_np, leaf_size)
        construction_time_sum += time.time() - begin_t

        query = np.random.rand(3)

        begin_t = time.time()
        result_set = KNNResultSet(capacity=k)
        kdtree.kdtree_knn_search(root, db_np, result_set, query)
        knn_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set = RadiusNNResultSet(radius=radius)
        kdtree.kdtree_radius_search(root, db_np, result_set, query)
        radius_time_sum += time.time() - begin_t

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
    print("Kdtree: build %.3f, knn %.3f, radius %.3f, brute %.3f" %
          (construction_time_sum * 1000 / iteration_num, knn_time_sum * 1000 /
           iteration_num, radius_time_sum * 1000 / iteration_num,
           brute_time_sum * 1000 / iteration_num))
예제 #2
0
def main():
    # configuration
    leaf_size = 32
    min_extent = 0.0001
    k = 8
    radius = 1

    root_dir = './velodyne'  # 数据集路径
    cat = os.listdir(root_dir)
    iteration_num = len(cat)



    print("scipy-KDTree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    for i in range(iteration_num):
        filename = os.path.join(root_dir, cat[i])
        db_np = read_velodyne_bin(filename)
        # print(db_np.shape)

        begin_t = time.time()
        tree = KDTree(db_np, leafsize=leaf_size)
        construction_time_sum += time.time() - begin_t

        query = db_np[222, :]

        begin_t = time.time()
        distance, indices = tree.query(x=query, k=k)
        print(distance)
        print(indices)
        knn_time_sum += time.time() - begin_t


        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
        # print(nn_idx)


    print("Octree: build %.3f, knn %.3f, brute %.3f" % (construction_time_sum*1000/iteration_num,
                                                                     knn_time_sum*1000/iteration_num,
                                                                     brute_time_sum*1000/iteration_num))


    print("octree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    for i in range(iteration_num):
        filename = os.path.join(root_dir, cat[i])
        db_np = read_velodyne_bin(filename)

        begin_t = time.time()
        root = octree.octree_construction(db_np, leaf_size, min_extent)
        construction_time_sum += time.time() - begin_t

        query = db_np[222, :]

        begin_t = time.time()
        result_set = KNNResultSet(capacity=k)
        octree.octree_knn_search(root, db_np, result_set, query)
        print("result ------------")
        print(result_set)
        knn_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set = RadiusNNResultSet(radius=radius)
        octree.octree_radius_search_fast(root, db_np, result_set, query)
        # print("result ------------")
        # print(result_set)
        radius_time_sum += time.time() - begin_t

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
        # print(nn_idx)

    print("Octree: build %.3f, knn %.3f, radius %.3f, brute %.3f" % (construction_time_sum*1000/iteration_num,
                                                                     knn_time_sum*1000/iteration_num,
                                                                     radius_time_sum*1000/iteration_num,
                                                                     brute_time_sum*1000/iteration_num))
    otc_knn = knn_time_sum*1000
    otc_radius = radius_time_sum*1000
    otc_brute = brute_time_sum*1000

    print("kdtree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    for i in range(iteration_num):
        filename = os.path.join(root_dir, cat[i])
        db_np = read_velodyne_bin(filename)

        begin_t = time.time()
        root = kdtree.kdtree_construction(db_np, leaf_size)
        construction_time_sum += time.time() - begin_t

        query = db_np[222, :]

        begin_t = time.time()
        result_set = KNNResultSet(capacity=k)
        kdtree.kdtree_knn_search(root, db_np, result_set, query)
        knn_time_sum += time.time() - begin_t
        print("result ------------")
        print(result_set)

        begin_t = time.time()
        result_set = RadiusNNResultSet(radius=radius)
        kdtree.kdtree_radius_search(root, db_np, result_set, query)
        radius_time_sum += time.time() - begin_t
        # print("result ------------")
        # print(result_set)

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
        # print(nn_idx)


    kd_knn = knn_time_sum * 1000
    kd_radius = radius_time_sum * 1000
    kd_brute = brute_time_sum * 1000

    print("Kdtree: build %.3f, knn %.3f, radius %.3f, brute %.3f" % (construction_time_sum * 1000 / iteration_num,
                                                                     knn_time_sum * 1000 / iteration_num,
                                                                     radius_time_sum * 1000 / iteration_num,
                                                                     brute_time_sum * 1000 / iteration_num))

    print("Octree knn/brute =  %.3f,   radius/bruet = %.3f" % (otc_knn/otc_brute, otc_radius/otc_brute))
    print("Kdtree knn/brute =  %.3f,   radius/bruet = %.3f" % (kd_knn / kd_brute, kd_radius / kd_brute))
예제 #3
0
def main():
    # configuration
    leaf_size = 32
    min_extent = 0.001
    k = 8
    radius = 1

    root_dir = '/home/xcy/myWork/pointCloudProcessing/lesson2/bin'  # 数据集路径
    cat = os.listdir(root_dir)
    iteration_num = len(cat)

    print("octree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    radius_fast_time_sum = 0
    brute_time_sum = 0
    for i in range(iteration_num):
        filename = os.path.join(root_dir, cat[i])
        db_np = read_velodyne_bin(filename)

        begin_t = time.time()
        root = octree.octree_construction(db_np, leaf_size, min_extent)
        construction_time_sum += time.time() - begin_t

        query = db_np[0, :]

        begin_t = time.time()
        result_set = KNNResultSet(capacity=k)
        octree.octree_knn_search(root, db_np, result_set, query)
        knn_time_sum += time.time() - begin_t
        #
        begin_t = time.time()
        result_set = RadiusNNResultSet(radius=radius)
        octree.octree_radius_search(root, db_np, result_set, query)
        radius_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set = RadiusNNResultSet(radius=radius)
        octree.octree_radius_search_fast(root, db_np, result_set, query)
        radius_fast_time_sum += time.time() - begin_t

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
    print(
        "Octree: build %.3f, knn %.3f, radius %.3f, radius_fast %.3f, brute %.3f"
        % (construction_time_sum * 1000 / iteration_num, knn_time_sum * 1000 /
           iteration_num, radius_time_sum * 1000 / iteration_num,
           radius_fast_time_sum * 1000 / iteration_num,
           brute_time_sum * 1000 / iteration_num))

    print("kdtree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    for i in range(iteration_num):
        filename = os.path.join(root_dir, cat[i])
        db_np = read_velodyne_bin(filename)

        begin_t = time.time()
        root = kdtree.kdtree_construction(db_np, leaf_size)
        construction_time_sum += time.time() - begin_t

        #        begin_t = time.time()
        #        root = kdtree.kdtree_construction_median(db_np, leaf_size)
        #        construction_time_sum += time.time() - begin_t

        query = db_np[0, :]

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set = KNNResultSet(capacity=k)
        kdtree.kdtree_knn_search(root, db_np, result_set, query)
        knn_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set = RadiusNNResultSet(radius=radius)
        kdtree.kdtree_radius_search(root, db_np, result_set, query)
        radius_time_sum += time.time() - begin_t

    print("Kdtree: build %.3f, knn %.3f, radius %.3f, brute %.3f" %
          (construction_time_sum * 1000 / iteration_num, knn_time_sum * 1000 /
           iteration_num / (brute_time_sum * 1000 / iteration_num),
           radius_time_sum * 1000 / iteration_num /
           (brute_time_sum * 1000 / iteration_num),
           brute_time_sum * 1000 / iteration_num))
예제 #4
0
def main():
    # configuration
    leaf_size = 32
    min_extent = 0.0001
    k = 8
    radius = 1

    # data
    root_dir = '../data/bin'
    cat = os.listdir(root_dir)
    iteration_num = len(cat)

    print("Brute-force --------------")
    brute_time_sum = 0
    for i in range(iteration_num):
        filename = os.path.join(root_dir, cat[i])
        db_np = read_velodyne_bin(filename)

        query = db_np[0, :]

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
    print("Brute-force: %.3f" % (brute_time_sum * 1000 / iteration_num))

    # scipy.spatial.KDTree
    print("scipy.spatial.KDTree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    for i in range(iteration_num):
        filename = os.path.join(root_dir, cat[i])
        db_np = read_velodyne_bin(filename)

        begin_t = time.time()
        tree = spatial.KDTree(db_np, leaf_size)
        construction_time_sum += time.time() - begin_t

        query = db_np[0, :]

        begin_t = time.time()
        res = tree.query(query, k)
        knn_time_sum += time.time() - begin_t
    print("scipy.spatial.KDTree: build %.3f, knn %.3f" %
          (construction_time_sum * 1000 / iteration_num,
           knn_time_sum * 1000 / iteration_num))

    print("Octree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    for i in range(iteration_num):
        filename = os.path.join(root_dir, cat[i])
        db_np = read_velodyne_bin(filename)

        begin_t = time.time()
        root = octree.octree_construction(db_np, leaf_size, min_extent)
        construction_time_sum += time.time() - begin_t

        query = db_np[0, :]

        begin_t = time.time()
        result_set = KNNResultSet(capacity=k)
        octree.octree_knn_search(root, db_np, result_set, query)
        knn_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set = RadiusNNResultSet(radius=radius)
        octree.octree_radius_search_fast(root, db_np, result_set, query)
        radius_time_sum += time.time() - begin_t

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
    print("Octree: build %.3f, knn %.3f, radius %.3f, brute %.3f" %
          (construction_time_sum * 1000 / iteration_num, knn_time_sum * 1000 /
           iteration_num, radius_time_sum * 1000 / iteration_num,
           brute_time_sum * 1000 / iteration_num))

    print("KD-Tree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    for i in range(iteration_num):
        filename = os.path.join(root_dir, cat[i])
        db_np = read_velodyne_bin(filename)

        begin_t = time.time()
        root = kdtree.kdtree_construction(db_np, leaf_size)
        construction_time_sum += time.time() - begin_t

        query = db_np[0, :]

        begin_t = time.time()
        result_set = KNNResultSet(capacity=k)
        kdtree.kdtree_knn_search(root, db_np, result_set, query)
        knn_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set = RadiusNNResultSet(radius=radius)
        kdtree.kdtree_radius_search(root, db_np, result_set, query)
        radius_time_sum += time.time() - begin_t

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
    print("KD-Tree: build %.3f, knn %.3f, radius %.3f, brute %.3f" %
          (construction_time_sum * 1000 / iteration_num, knn_time_sum * 1000 /
           iteration_num, radius_time_sum * 1000 / iteration_num,
           brute_time_sum * 1000 / iteration_num))
예제 #5
0
def main():
    # configuration
    leaf_size = 32
    min_extent = 0.0001
    k = 8
    radius = 1
    filename = '000000.bin'
    db_np = read_velodyne_bin(filename)
    iteration_num = 1
    cat = []

    print("octree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    for i in range(iteration_num):
        db_np = read_velodyne_bin(filename)

        begin_t = time.time()
        root = octree.octree_construction(db_np, leaf_size, min_extent)
        construction_time_sum += time.time() - begin_t

        query = db_np[0, :]

        begin_t = time.time()
        result_set = KNNResultSet(capacity=k)
        octree.octree_knn_search(root, db_np, result_set, query)
        knn_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set = RadiusNNResultSet(radius=radius)
        octree.octree_radius_search_fast(root, db_np, result_set, query)
        radius_time_sum += time.time() - begin_t

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
    print("Octree: build %.3f, knn %.3f, radius %.3f, brute %.3f" %
          (construction_time_sum * 1000 / iteration_num, knn_time_sum * 1000 /
           iteration_num, radius_time_sum * 1000 / iteration_num,
           brute_time_sum * 1000 / iteration_num))

    print("kdtree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    for i in range(iteration_num):
        #filename = os.path.join(root_dir, cat[i])
        db_np = read_velodyne_bin(filename)

        begin_t = time.time()
        root = kdtree.kdtree_construction(db_np, leaf_size)
        construction_time_sum += time.time() - begin_t

        query = db_np[0, :]

        begin_t = time.time()
        result_set = KNNResultSet(capacity=k)
        kdtree.kdtree_knn_search(root, db_np, result_set, query)
        knn_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set = RadiusNNResultSet(radius=radius)
        kdtree.kdtree_radius_search(root, db_np, result_set, query)
        radius_time_sum += time.time() - begin_t

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
    print("Kdtree: build %.3f, knn %.3f, radius %.3f, brute %.3f" %
          (construction_time_sum * 1000 / iteration_num, knn_time_sum * 1000 /
           iteration_num, radius_time_sum * 1000 / iteration_num,
           brute_time_sum * 1000 / iteration_num))
예제 #6
0
def main():
    # configuration
    leaf_size = 32
    min_extent = 0.0001
    k = 8
    radius = 1.0

    root_dir = './'  # 数据集路径
    files = os.listdir(root_dir)

    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    iteration_num = 0
    for file in files:
        if file.find('bin') == -1:
            continue
        iteration_num += 1
        filename = os.path.join(root_dir, file)
        db_np = read_velodyne_bin(filename)
        #point_indices=np.array([1,2,3,4,5,6,7])
        #db_larger=point_indices[db_np[point_indices,1]>0.4]
        #db_larger_idx=np.where
        #print("test data",db_np[point_indices,1])
        #print("test index",db_np[point_indices,1]>0.4)
        #print("test1",db_larger,db_np[db_larger,1])

        begin_t = time.time()
        root = octree.octree_construction(db_np, leaf_size, min_extent)
        construction_time_sum += time.time() - begin_t

        query = db_np[0, :]

        begin_t = time.time()
        result_set = KNNResultSet(capacity=k)
        octree.octree_knn_search(root, db_np, result_set, query)
        knn_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set = RadiusNNResultSet(radius=radius)
        octree.octree_radius_search_fast(root, db_np, result_set, query)
        radius_time_sum += time.time() - begin_t

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
    print("Octree: build %.3f, knn %.3f, radius %.3f, brute %.3f" %
          (construction_time_sum * 1000 / iteration_num, knn_time_sum * 1000 /
           iteration_num, radius_time_sum * 1000 / iteration_num,
           brute_time_sum * 1000 / iteration_num))

    print("--------------")
    KDTreeBenchmark(root_dir, files, k, leaf_size, radius)
    print("--------------")
    KDTreeBenchmark(root_dir, files, k, leaf_size, radius, "mean")
    print("--------------")
    KDTreeBenchmark(root_dir, files, k, leaf_size, radius, "meanraw")

    print("--------------")
    KDTreeBenchmark(root_dir, files, k, leaf_size, radius, "median", "adapt")
    print("--------------")
    KDTreeBenchmark(root_dir, files, k, leaf_size, radius, "meanraw", "adapt")
    print("--------------")
    KDTreeBenchmark(root_dir, files, k, leaf_size, radius, "mean", "adapt")

    # construction_time_sum = 0
    # knn_time_sum = 0
    # radius_time_sum = 0
    # brute_time_sum = 0
    # iteration_num = 0
    # for file in files:
    #     if file.find('bin') == -1:
    #         continue
    #     iteration_num += 1
    #     filename = os.path.join(root_dir, file)
    #     db_np = read_velodyne_bin(filename)

    #     begin_t = time.time()
    #     root = kdtree.kdtree_construction(db_np, leaf_size)
    #     construction_time_sum += time.time() - begin_t

    #     query = db_np[0,:]

    #     begin_t = time.time()
    #     result_set = KNNResultSet(capacity=k)
    #     kdtree.kdtree_knn_search(root, db_np, result_set, query)
    #     print("result set from KD Tree\n",result_set)
    #     knn_time_sum += time.time() - begin_t
    #     # print("--------")
    #     begin_t = time.time()
    #     result_set = RadiusNNResultSet(radius=radius)
    #     kdtree.kdtree_radius_search(root, db_np, result_set, query)
    #     #print(result_set)
    #     radius_time_sum += time.time() - begin_t
    #     #print("--------")
    #     begin_t = time.time()
    #     diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
    #     nn_idx = np.argsort(diff)
    #     nn_dist = diff[nn_idx]
    #     #print(nn_idx[0:k])
    #     #print(nn_dist[0:k])
    #     brute_time_sum += time.time() - begin_t
    #     depth = [0]
    #     max_depth = [0]
    #     kdtree.traverse_kdtree(root, depth, max_depth)
    #     print("tree depth: %d, max depth: %d" % (depth[0],max_depth[0]))
    # print("Kdtree: build %.3f, knn %.3f, radius %.3f, brute %.3f" % (construction_time_sum * 1000 / iteration_num,
    #                                                                     knn_time_sum * 1000 / iteration_num,
    #                                                                     radius_time_sum * 1000 / iteration_num,
    #                                                                     brute_time_sum * 1000 / iteration_num))

    print("--------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    iteration_num = 0
    for file in files:
        if file.find('bin') == -1:
            continue
        iteration_num += 1
        filename = os.path.join(root_dir, file)
        db_np = read_velodyne_bin(filename)

        begin_t = time.time()
        tree = KDTree(db_np)
        construction_time_sum += time.time() - begin_t

        query = db_np[0, :]

        begin_t = time.time()
        result_set = tree.query(([query[0], query[1], query[2]]), k=k, p=2)
        print("result set", result_set)
        knn_time_sum += time.time() - begin_t
        # print("--------")
        begin_t = time.time()
        result_set = tree.query_ball_point(([query[0], query[1], query[2]]),
                                           radius)
        # print(result_set)
        radius_time_sum += time.time() - begin_t
        # print("--------")
        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
        print("scipy idx", nn_idx[0:k])
        print("scipy dist", nn_dist[0:k])
    print("Scipy Kdtree: build %.3f, knn %.3f, radius %.3f, brute %.3f" %
          (construction_time_sum * 1000 / iteration_num, knn_time_sum * 1000 /
           iteration_num, radius_time_sum * 1000 / iteration_num,
           brute_time_sum * 1000 / iteration_num))
예제 #7
0
def main():
    # configuration
    leaf_size = 32
    min_extent = 0.0001
    k = 8
    radius = 1

    root_dir = '/home/gc/github_repository/DeepBlue/lesson_2/kitty/' # 数据集路径
    cat = os.listdir(root_dir)
    iteration_num = len(cat)

    print("octree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    for i in range(iteration_num):
        filename = os.path.join(root_dir, cat[i])
        db_np = read_velodyne_bin(filename)
        db_np = db_np.T

        begin_t = time.time()
        root = octree.octree_construction(db_np, leaf_size, min_extent)
        construction_time_sum += time.time() - begin_t

        query = db_np[0,:]

        begin_t = time.time()
        result_set = KNNResultSet(capacity=k)
        octree.octree_knn_search(root, db_np, result_set, query)
        knn_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set = RadiusNNResultSet(radius=radius)
        octree.octree_radius_search_fast(root, db_np, result_set, query)
        radius_time_sum += time.time() - begin_t

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
    print("Octree: build %.3f, knn %.3f, radius %.3f, brute %.3f" % (construction_time_sum*1000/iteration_num,
                                                                     knn_time_sum*1000/iteration_num,
                                                                     radius_time_sum*1000/iteration_num,
                                                                     brute_time_sum*1000/iteration_num))

    otc_knn = knn_time_sum*1000
    otc_radius = radius_time_sum*1000
    otc_brute = brute_time_sum*1000

    print("kdtree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    for i in range(iteration_num):
        filename = os.path.join(root_dir, cat[i])
        db_np = read_velodyne_bin(filename)

        begin_t = time.time()
        root = kdtree.kdtree_construction(db_np, leaf_size)
        construction_time_sum += time.time() - begin_t

        query = db_np[0,:]

        begin_t = time.time()
        result_set = KNNResultSet(capacity=k)
        kdtree.kdtree_knn_search(root, db_np, result_set, query)
        knn_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set = RadiusNNResultSet(radius=radius)
        kdtree.kdtree_radius_search(root, db_np, result_set, query)
        radius_time_sum += time.time() - begin_t

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t
    print("Kdtree: build %.3f, knn %.3f, radius %.3f, brute %.3f" % (construction_time_sum * 1000 / iteration_num,
                                                                     knn_time_sum * 1000 / iteration_num,
                                                                     radius_time_sum * 1000 / iteration_num,
                                                                     brute_time_sum * 1000 / iteration_num))
    kd_knn = knn_time_sum * 1000
    kd_radius = radius_time_sum * 1000
    kd_brute = brute_time_sum * 1000

    print("Octree knn/brute =  %.3f,   radius/bruet = %.3f" % (otc_knn/otc_brute, otc_radius/otc_brute) )
    print("Kdtree knn/brute =  %.3f,   radius/bruet = %.3f" % (kd_knn / otc_brute, kd_radius / otc_brute) )
def main():
    # configuration
    leaf_size = 32
    min_extent = 0.0001
    k = 8
    radius = 1

    #root_dir = '/Users/renqian/cloud_lesson/kitti' # 数据集路径
    #cat = os.listdir(root_dir)
    #iteration_num = len(cat)
    # load date
    filename = '/home/ljn/SLAM/dateset/000000.bin'
    db_np = read_velodyne_bin(filename)
    iteration = 1

    print("octree -----------------------------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    result_set_knn = KNNResultSet(capacity=k)
    query = db_np[95, :]

    begin_t = time.time()
    root = octree.octree_construction(db_np, leaf_size, min_extent)
    construction_time_sum += time.time() - begin_t

    begin_t = time.time()

    octree.octree_knn_search(root, db_np, result_set_knn, query)
    knn_time_sum += time.time() - begin_t
    print('knn search result\n', result_set_knn)

    begin_t = time.time()
    result_set_rnn = RadiusNNResultSet(radius=radius)
    octree.octree_radius_search_fast(root, db_np, result_set_rnn, query)
    radius_time_sum += time.time() - begin_t
    print('rnn search result\n', result_set_rnn)

    begin_t = time.time()
    diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
    nn_idx = np.argsort(diff)
    nn_dist = diff[nn_idx]
    nn_dist_idx_pre = np.linspace(0, nn_dist.shape[0], nn_dist.shape[0])
    nn_dist_idx = nn_dist_idx_pre[nn_idx]
    brute_time_sum += time.time() - begin_t

    #brute knn search
    result_set_knn_brute = KNNResultSet(capacity=k)
    for index in range(k):
        result_set_knn_brute.add_point(nn_dist[index], nn_dist_idx[index])
    # brute radiusNN search
    result_set_rnn_brute = RadiusNNResultSet(radius=radius)
    for index in range(nn_dist.shape[0]):
        if nn_dist[index] < radius:
            result_set_rnn_brute.add_point(nn_dist[index], nn_dist_idx[index])
            continue
        else:
            break

    print("Octree: build %.3f, knn %.3f, radius %.3f, brute %.3f" %
          (construction_time_sum * 1000, knn_time_sum * 1000,
           radius_time_sum * 1000, brute_time_sum * 1000))

    print("kdtree -----------------------------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    for i in range(iteration):
        query = db_np[95, :]

        begin_t = time.time()
        root = kdtree.kdtree_construction(db_np, leaf_size)
        construction_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set_knn = KNNResultSet(capacity=k)
        kdtree.kdtree_knn_search(root, db_np, result_set_knn, query)
        knn_time_sum += time.time() - begin_t

        begin_t = time.time()
        result_set_rnn = RadiusNNResultSet(radius=radius)
        kdtree.kdtree_radius_search(root, db_np, result_set_rnn, query)
        radius_time_sum += time.time() - begin_t

        begin_t = time.time()
        diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
        nn_idx = np.argsort(diff)
        nn_dist = diff[nn_idx]
        brute_time_sum += time.time() - begin_t

        nn_dist_idx_pre = np.linspace(0, nn_dist.shape[0] - 1,
                                      nn_dist.shape[0])
        nn_dist_idx = nn_dist_idx_pre[nn_idx]
        # brute knn search
        result_set_knn_brute = KNNResultSet(capacity=k)
        for index in range(k):
            result_set_knn_brute.add_point(nn_dist[index], nn_dist_idx[index])
        # brute radiusNN search
        result_set_rnn_brute = RadiusNNResultSet(radius=radius)
        for index in range(nn_dist.shape[0]):
            if nn_dist[index] < radius:
                result_set_rnn_brute.add_point(nn_dist[index],
                                               nn_dist_idx[index])
                continue
            else:
                break
    print("Kdtree: build %.3f, knn %.3f, radius %.3f, brute %.3f" %
          (construction_time_sum * 1000, knn_time_sum * 1000,
           radius_time_sum * 1000, brute_time_sum * 1000))

    print("scipy kdtree  -----------------------------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0

    query = db_np[95, :]

    begin_t = time.time()
    tree = spatial.KDTree(db_np, leaf_size)
    construction_time_sum += time.time() - begin_t

    #no knn
    begin_t = time.time()
    knn_time_sum += time.time() - begin_t

    begin_t = time.time()
    result_set_rnn = tree.query_ball_point(query, radius)
    radius_time_sum += time.time() - begin_t
    print('rnn search result\n', result_set_rnn)

    print("Octree: build %.3f, knn %.3f, radius %.3f" %
          (construction_time_sum * 1000, knn_time_sum * 1000,
           radius_time_sum * 1000))
예제 #9
0
def main():
    # configuration
    leaf_size = 32
    min_extent = 0.0001
    k = 8
    radius = 1

    # root_dir = './Users/renqian/cloud_lesson/kitti' # 数据集路径
    # cat = os.listdir(root_dir)
    # iteration_num = len(cat)

    print("octree --------------")
    construction_time_sum = 0
    knn_time_sum = 0
    radius_time_sum = 0
    brute_time_sum = 0
    # for i in range(iteration_num):
    #     filename = os.path.join(root_dir, cat[i])
    #     db_np = read_velodyne_bin(filename)
    #
    #     begin_t = time.time()
    #     root = octree.octree_construction(db_np, leaf_size, min_extent)
    #     construction_time_sum += time.time() - begin_t
    #
    #     query = db_np[0,:]
    #
    #     begin_t = time.time()
    #     result_set = KNNResultSet(capacity=k)
    #     octree.octree_knn_search(root, db_np, result_set, query)
    #     knn_time_sum += time.time() - begin_t
    #
    #     begin_t = time.time()
    #     result_set = RadiusNNResultSet(radius=radius)
    #     octree.octree_radius_search_fast(root, db_np, result_set, query)
    #     radius_time_sum += time.time() - begin_t
    #
    #     begin_t = time.time()
    #     diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
    #     nn_idx = np.argsort(diff)
    #     nn_dist = diff[nn_idx]
    #     brute_time_sum += time.time() - begin_t
    filename = './000000.bin'
    db_np = read_velodyne_bin(filename)

    begin_t = time.time()
    root = octree.octree_construction(db_np, leaf_size, min_extent)
    construction_time_sum += time.time() - begin_t

    query = db_np[0, :]

    begin_t = time.time()
    result_set = KNNResultSet(capacity=k)
    octree.octree_knn_search(root, db_np, result_set, query)
    knn_time_sum += time.time() - begin_t

    begin_t = time.time()
    result_set = RadiusNNResultSet(radius=radius)
    octree.octree_radius_search_fast(root, db_np, result_set, query)
    radius_time_sum += time.time() - begin_t

    begin_t = time.time()
    diff = np.linalg.norm(np.expand_dims(query, 0) - db_np, axis=1)
    nn_idx = np.argsort(diff)
    nn_dist = diff[nn_idx]
    brute_time_sum += time.time() - begin_t
    print("Octree: build %.3f, knn %.3f, radius %.3f, brute %.3f" %
          (construction_time_sum * 1000, knn_time_sum * 1000,
           radius_time_sum * 1000, brute_time_sum * 1000))

    begin_t = time.time()
    result_set = RadiusNNResultSet(radius=radius)
    octree.octree_radius_search_plus(root, db_np, result_set, query)
    radius_time_sum += time.time() - begin_t

    print("Octree: radius_plus %.3f" % (radius_time_sum * 1000))