def ViewPLY(path): # 読み込み pointcloud = open3d.read_point_cloud(path) # ダウンサンプリング # 法線推定できなくなるので不採用 pointcloud = open3d.voxel_down_sample(pointcloud, 10) # 法線推定 open3d.estimate_normals(pointcloud, search_param=open3d.KDTreeSearchParamHybrid( radius=20, max_nn=30)) # 法線の方向を視点ベースでそろえる open3d.orient_normals_towards_camera_location(pointcloud, camera_location=np.array( [0., 10., 10.], dtype="float64")) # 可視化 open3d.draw_geometries([pointcloud]) # numpyに変換 points = np.asarray(pointcloud.points) normals = np.asarray(pointcloud.normals) print("points:{}".format(points.shape[0])) X, Y, Z = Disassemble(points) # OBB生成 _, _, length = buildOBB(points) print("OBB_length: {}".format(length)) return points, X, Y, Z, normals, length
def NormalEstimate(points): """ 法線推定 """ #点群をnp配列⇒open3d形式に pointcloud = open3d.PointCloud() pointcloud.points = open3d.Vector3dVector(points) # 法線推定 open3d.estimate_normals(pointcloud, search_param=open3d.KDTreeSearchParamHybrid( radius=5, max_nn=30)) # 法線の方向を視点ベースでそろえる open3d.orient_normals_towards_camera_location(pointcloud, camera_location=np.array( [0., 10., 10.], dtype="float64")) #nキーで法線表示 #open3d.draw_geometries([pointcloud]) #法線をnumpyへ変換 normals = np.asarray(pointcloud.normals) return normals
def NormalEstimate(points): #objファイルから点群取得 # points = loadOBJ(path) print("points:{}".format(points.shape[0])) #点群をnp配列⇒open3d形式に pointcloud = open3d.PointCloud() pointcloud.points = open3d.Vector3dVector(points) # 法線推定 open3d.estimate_normals(pointcloud, search_param=open3d.KDTreeSearchParamHybrid( radius=5, max_nn=30)) # 法線の方向を視点ベースでそろえる open3d.orient_normals_towards_camera_location(pointcloud, camera_location=np.array( [0., 10., 10.], dtype="float64")) #nキーで法線表示 #open3d.draw_geometries([pointcloud]) #法線をnumpyへ変換 normals = np.asarray(pointcloud.normals) #OBB生成 #(最適化の条件にも使いたい) # _, _, length = buildOBB(points) # print("OBB_length: {}".format(length)) return normals
def preprocess_point_cloud(pointcloud, voxel_size): keypoints = open3d.voxel_down_sample(pointcloud, voxel_size) radius_normal = voxel_size * 2 view_point = np.array([0., 10., 10.], dtype="float64") open3d.estimate_normals(keypoints, search_param=open3d.KDTreeSearchParamHybrid( radius=radius_normal, max_nn=30)) open3d.orient_normals_towards_camera_location(keypoints, camera_location=view_point) radius_feature = voxel_size * 5 fpfh = open3d.compute_fpfh_feature( keypoints, search_param=open3d.KDTreeSearchParamHybrid(radius=radius_feature, max_nn=100)) return keypoints, fpfh
def PreProcess2(): #自作した点群を読み込み points, X, Y, Z = MakePoints(sample_plane, bbox=(-1.5, 1), grid_step=80, epsilon=0.03, down_rate=0.5) print("points:{}".format(len(X))) #点群をnp配列⇒open3d形式に pointcloud = open3d.PointCloud() pointcloud.points = open3d.Vector3dVector(points) # 法線推定 open3d.estimate_normals(pointcloud, search_param=open3d.KDTreeSearchParamHybrid( radius=1, max_nn=30)) # 法線の方向を視点ベースでそろえる open3d.orient_normals_towards_camera_location(pointcloud, camera_location=np.array( [0., 10., 10.], dtype="float64")) #nキーで法線表示 #open3d.draw_geometries([pointcloud]) #法線をnumpyへ変換 normals = np.asarray(pointcloud.normals) #OBB生成 #(最適化の条件にも使いたい) _, _, length = buildOBB(points) print("OBB_length: {}".format(length)) return points, X, Y, Z, normals, length
noise = np.array([[Random(xmin, xmax), Random(ymin, ymax), Random(zmin, zmax)] for i in range(n_size)]) points = np.concatenate([points, noise]) size = points.shape[0] #点群をnp配列⇒open3d形式に pointcloud = open3d.PointCloud() pointcloud.points = open3d.Vector3dVector(points) # color colors3 = np.asarray(pointcloud.colors) print(colors3.shape) colors3 = np.array([[255, 130, 0] if i < p_size else [0, 0, 255] for i in range(size)]) / 255 pointcloud.colors = open3d.Vector3dVector(colors3) # 法線推定 open3d.estimate_normals(pointcloud, search_param=open3d.KDTreeSearchParamHybrid( radius=5, max_nn=100)) # 法線の方向を視点ベースでそろえる open3d.orient_normals_towards_camera_location(pointcloud, camera_location=np.array( [0., 10., 10.], dtype="float64")) #nキーで法線表示 open3d.draw_geometries([pointcloud])
maxR = 0.55 maxitteration = 1000 threshould = 0.05 start = time.time() for i in range(1): pcd = o3d.io.read_point_cloud("stright.ply") #pcd=o3d.io.read_point_cloud("cylinderPLY/"+str(i+1)+"cylinder2m.ply") o3d.geometry.estimate_normals( pcd, search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.5, max_nn=10000)) #法線ベクトルを視点方向に揃える o3d.orient_normals_towards_camera_location(pcd, camera_location=np.array( [0., 0., 1000.], dtype="float64")) #o3d.visualization.draw_geometries([pcd]) point = np.asarray(pcd.points) normal = np.asarray(pcd.normals) maxinliner = 0 itteration = 0 #RANSAC while itteration < maxitteration: sample = random.sample(range(len(point)), 2) a = sample[0] b = sample[1] p1 = np.array(pcd.points[a])