Commit 0d5436b9 authored by Paul Brust's avatar Paul Brust
Browse files

fix dbscan

parent 775e431f
......@@ -3,6 +3,7 @@ from pathlib import Path
import pandas as pd
import open3d as o3d
import matplotlib.pyplot as plt
import numpy as np
import utils
......@@ -52,8 +53,7 @@ def get_plane_segmentation_and_bounding_boxes(input_data, distance_threshold=0.0
return walls, hulls
def do_plane_segmentation(data_directory: str, floor_name: str, results_directory: str):
error_percentage = 0.2
def collect_data_sets(data_directory, floor_name):
full_data = []
floor_directory = str(Path(data_directory) / Path(floor_name))
......@@ -62,6 +62,12 @@ def do_plane_segmentation(data_directory: str, floor_name: str, results_director
full_data.append(input_data)
print(f"{len(full_data)} data sets read in from {floor_directory}")
return full_data
def do_plane_segmentation(data_directory: str, floor_name: str, results_directory: str):
error_percentage = 0.15
full_data = collect_data_sets(data_directory, floor_name)
floor_heights = utils.get_floors(pd.concat(full_data))
......@@ -86,21 +92,42 @@ def do_plane_segmentation(data_directory: str, floor_name: str, results_director
o3d.io.write_point_cloud(f"{results_directory}{floor_name}/result_wall_{i}.xyz", wall)
def main_DBSCAN_clustering():
input_data = pd.read_csv("datasets/OneFloor_Full.csv")
utils.do_open3d_clustering(input_data, 0.15, 200)
def do_DBSCAN_clustering(data_directory, floor_name):
error_percentage = 0.15
voxel_size = 0.1
eps = 0.5
min_points = 50
data_sets = collect_data_sets(data_directory, floor_name)
input_data = pd.concat(data_sets)
floor_heights = utils.get_floors(input_data)
input_data = utils.filter_for_walls(input_data, floor_heights, error_percentage)
point_cloud = o3d.geometry.PointCloud()
point_cloud.points = o3d.utility.Vector3dVector(input_data[["//X", "Y", "Z"]].to_numpy())
pcd = point_cloud.voxel_down_sample(voxel_size=voxel_size)
with o3d.utility.VerbosityContextManager(o3d.utility.VerbosityLevel.Debug) as cm:
labels = np.array(pcd.cluster_dbscan(eps=eps, min_points=min_points, print_progress=True))
max_label = labels.max()
print(f"point cloud has {max_label + 1} clusters")
colors = plt.get_cmap("tab20")(labels / (max_label if max_label > 0 else 1))
colors[labels < 0] = 0
pcd.colors = o3d.utility.Vector3dVector(colors[:, :3])
o3d.visualization.draw_geometries([pcd])
if __name__ == '__main__':
floors_directory = "./datasets/floors/"
results_directory = "./results/walls/"
# floor_name = "Floor_1"
#
# os.makedirs(f"{results_directory}{floor_name}")
#
# do_plane_segmentation(floors_directory, floor_name, results_directory)
for floor_name in os.listdir(floors_directory):
os.makedirs(f"{results_directory}{floor_name}")
# do_DBSCAN_clustering(floors_directory, floor_name)
try:
os.mkdir(f"{results_directory}{floor_name}")
except:
pass
do_plane_segmentation(floors_directory, floor_name, results_directory)
......@@ -38,18 +38,3 @@ def display_inlier_outlier(cloud, ind):
outlier_cloud.paint_uniform_color([1, 0, 0])
inlier_cloud.paint_uniform_color([0.8, 0.8, 0.8])
o3d.visualization.draw_geometries([inlier_cloud, outlier_cloud])
def do_open3d_clustering(input_data, eps, min_points):
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(input_data[["X", "Y", "Z"]].to_numpy())
with o3d.utility.VerbosityContextManager(o3d.utility.VerbosityLevel.Debug) as cm:
labels = np.array(pcd.cluster_dbscan(eps=eps, min_points=min_points, print_progress=True))
max_label = labels.max()
print(f"point cloud has {max_label + 1} clusters")
colors = plt.get_cmap("tab20")(labels / (max_label if max_label > 0 else 1))
colors[labels < 0] = 0
pcd.colors = o3d.utility.Vector3dVector(colors[:, :3])
o3d.visualization.draw_geometries([pcd])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment