open3d的例程2

KDTree

Open3D使用FLANN来快速创建KDTrees

#src/Python/Tutorial/Basic/kdtree.py

 

import sys

import numpy as np

sys.path.append("../..")

from py3d import *

 

if __name__ =="__main__":

 

    print("Testing kdtree in py3d...")

    print("Load a point cloud and paint itgray.")

    pcd =read_point_cloud("../../TestData/Feature/cloud_bin_0.pcd")

    pcd.paint_uniform_color([0.5, 0.5, 0.5])

    pcd_tree = KDTreeFlann(pcd)

 

    print("Paint the 1500th pointred.")

    pcd.colors[1500] = [1, 0, 0]

 

    print("Find its 200 nearest neighbors,paint blue.")

    [k, idx, _] =pcd_tree.search_knn_vector_3d(pcd.points[1500], 200)

    np.asarray(pcd.colors)[idx[1:], :] = [0, 0,1]

 

    print("Find its neighbors withdistance less than 0.2, paint green.")

    [k, idx, _] = pcd_tree.search_radius_vector_3d(pcd.points[1500],0.2)

    np.asarray(pcd.colors)[idx[1:], :] = [0, 1,0]

 

    print("Visualize the pointcloud.")

    draw_geometries([pcd])

    print("")

point cloud来创建KDTree

print("Testingkdtree in py3d ...")

print("Load apoint cloud and paint it gray.")

pcd =read_point_cloud("../../TestData/Feature/cloud_bin_0.pcd")

pcd.paint_uniform_color([0.5,0.5, 0.5])

pcd_tree =KDTreeFlann(pcd)

上述脚本读取point cloud并构建一个KDTree。这是预处理步骤,对下述处理来说。

 

查找近邻点

print("Paintthe 1500th point red.")

pcd.colors[1500] =[1, 0, 0]

找到1500-th point,然后设定其像素值。

 

search_knn_vector_3d

print("Findits 200 nearest neighbors, paint blue.")

[k, idx, _] =pcd_tree.search_knn_vector_3d(pcd.points[1500], 200)

np.asarray(pcd.colors)[idx[1:],:] = [0, 0, 1]

函数search_knn_vector_3d返回anchor pointk近邻的list

 

search_radius_vector_3d

print("Findits neighbors with distance less than 0.2, paint green.")

[k, idx, _] =pcd_tree.search_radius_vector_3d(pcd.points[1500], 0.2)

np.asarray(pcd.colors)[idx[1:],:] = [0, 1, 0]

search_radius_vector_3d来查询所有点与anchorpoint的距离。
open3d的例程2_第1张图片

open3d的使用说明,参见https://www.toutiao.com/i6528559343925723661/

你可能感兴趣的:(图像标注,大数据,工具使用)