优化 import numpy as np import open3d as o3d from sklearn.cluster import DBSCAN # 读取点云数据 pcd = o3d.io.read_point_cloud("laser.pcd") points = np.asarray(pcd.points) # DBSCAN聚类 dbscan = DBSCAN(eps=0.2, min_samples=10) dbscan.fit(points) labels = dbscan.labels_ # 获取可行驶区域点云数据 drivable_mask = labels != -1 drivable_points = points[drivable_mask] # 获取路沿点云数据 curb_mask = np.logical_and(labels != -1, points[:, 1] < 0) curb_points = points[curb_mask] # 获取车道线点云数据 line_mask = np.logical_and(labels != -1, points[:, 1] >= 0) line_points = points[line_mask] # 可视化结果 drivable_pcd = o3d.geometry.PointCloud() drivable_pcd.points = o3d.utility.Vector3dVector(drivable_points) o3d.visualization.draw_geometries([drivable_pcd]) curb_pcd = o3d.geometry.PointCloud() curb_pcd.points = o3d.utility.Vector3dVector(curb_points) o3d.visualization.draw_geometries([curb_pcd]) line_pcd = o3d.geometry.PointCloud() line_pcd.points = o3d.utility.Vector3dVector(line_points) o3d.visualization.draw_geometries([line_pcd]) 加上预处理
时间: 2023-06-14 16:08:03 浏览: 138
python 3.74 运行import numpy as np 报错lib\site-packages\numpy\__init__.py
import numpy as np
import open3d as o3d
from sklearn.cluster import DBSCAN
# 读取点云数据
pcd = o3d.io.read_point_cloud("laser.pcd")
points = np.asarray(pcd.points)
# 预处理:去除离群点
mean = np.mean(points, axis=0)
std = np.std(points, axis=0)
inlier_mask = np.all(np.abs(points - mean) < 2 * std, axis=1)
points = points[inlier_mask]
# DBSCAN聚类
dbscan = DBSCAN(eps=0.2, min_samples=10)
dbscan.fit(points)
labels = dbscan.labels_
# 获取可行驶区域点云数据
drivable_mask = labels != -1
drivable_points = points[drivable_mask]
# 获取路沿点云数据
curb_mask = np.logical_and(labels != -1, points[:, 1] < 0)
curb_points = points[curb_mask]
# 获取车道线点云数据
line_mask = np.logical_and(labels != -1, points[:, 1] >= 0)
line_points = points[line_mask]
# 可视化结果
drivable_pcd = o3d.geometry.PointCloud()
drivable_pcd.points = o3d.utility.Vector3dVector(drivable_points)
o3d.visualization.draw_geometries([drivable_pcd])
curb_pcd = o3d.geometry.PointCloud()
curb_pcd.points = o3d.utility.Vector3dVector(curb_points)
o3d.visualization.draw_geometries([curb_pcd])
line_pcd = o3d.geometry.PointCloud()
line_pcd.points = o3d.utility.Vector3dVector(line_points)
o3d.visualization.draw_geometries([line_pcd])
阅读全文