python实现快速欧式聚类FEC:fast-euclidean-clustering
文章目录
- 前言
- 快速欧式聚类
- 效果
前言
欧式聚类因重复计算导致效率较低,快速欧式聚类有效提高效率。
参考论文:Cao Y, Wang Y, Xue Y, et al. FEC: Fast Euclidean Clustering for Point Cloud Segmentation[J]. Drones, 2022, 6(11): 325.
快速欧式聚类
import time
import numpy
import open3d as o3d
import numpy as np
import matplotlib.pyplot as plt
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)class PointIndex_NumberTag(object):def __init__(self):self.nPointIndex = 0.0self.nNumberTag = 0.0class Struct(object):def __init__(self, nPointIndex, nNumberTag):self.nPointIndex = nPointIndexself.nNumberTag = nNumberTagdef main():# 通过pcl.load加载pcd文件min_component_size = 100tolorance = 0.5max_n = 50start = time.perf_counter()cloud = o3d.io.read_point_cloud("../data/street.ply")cloud_tree = o3d.geometry.KDTreeFlann(cloud)point = numpy.asarray(cloud.points)size = len(point)marked_indices = [0] * sizeif size < min_component_size:raise("Could not find any cluster")else:print(cloud)tag_num = 1temp_tag_num = -1for i in range(size):if marked_indices[i] == 0:idx = [][k, idx, _] = cloud_tree.search_hybrid_vector_3d(cloud.points[i], tolorance, max_n)min_tag_num = tag_numfor j in idx:if (marked_indices[j] > 0) and (marked_indices[j] < min_tag_num):min_tag_num = marked_indices[j]for j in idx:temp_tag_num = marked_indices[j]if temp_tag_num > min_tag_num:for k in range(size):if marked_indices[k] == temp_tag_num:marked_indices[k] = min_tag_nummarked_indices[j] = min_tag_numtag_num += 1indices_tags = [[0]*2 for i in range(size)]for i in range(size):indices_tags[i][0] = iindices_tags[i][1] = marked_indices[i]indices_tags = sorted(indices_tags, key=lambda x:x[1])#indices_tags保存了每个聚类点云的索引和tag,下一步是根据索引提取点云,分开上色,并可视化begin_index = i = color_index = 0fianl_points = []for i in range(size):if indices_tags[i][1] != indices_tags[begin_index][1]:if i - begin_index >= min_component_size:for j in range(begin_index, i):fianl_points.append(point[indices_tags[j][0]][0])fianl_points.append(point[indices_tags[j][0]][1])fianl_points.append(point[indices_tags[j][0]][2])fianl_points.append(color_index)color_index += 1begin_index = iif indices_tags[i][1] != indices_tags[begin_index][1]: #最后一个聚类if i - begin_index >= min_component_size:for j in range(begin_index, i):fianl_points.append(point[indices_tags[j][0]][0])fianl_points.append(point[indices_tags[j][0]][1])fianl_points.append(point[indices_tags[j][0]][2])fianl_points.append(color_index)color_index += 1fianl_points = np.array(fianl_points)fianl_points = fianl_points.reshape(-1,4)end = time.perf_counter()print("running time: ", {end - start}, 'seconds')x = fianl_points[:,0]y = fianl_points[:,1]z = fianl_points[:,2]l = fianl_points[:,3]fig = plt.figure()ax = fig.add_subplot(111, projection='3d')fig.add_axes(ax)ax.scatter(x, # xy, # yz, # zl,c=l, # height data for colors = 2,marker = 'o',cmap='rainbow')plt.axis('off')ax.set_box_aspect([15,15,1])plt.show()if __name__ == "__main__":main()
效果
python实现快速欧式聚类FEC:fast-euclidean-clustering相关推荐
- 3D点云处理:点云聚类--FEC: Fast Euclidean Clustering for Point Cloud Segmentation
文章目录 聚类结果 一.论文内容 1.1 Ground Surface Removal 1.2 Fast Euclidean Clustering 题外:欧几里得聚类 Fast Euclidean C ...
- PCL 快速欧式聚类(FEC)
文章目录 一.简介 二.实现代码 三.实现效果 参考资料 一.简介 应一位同学的要求,出一版PCL的快速欧式聚类(FEC),该方法的具体原理可以参阅之前的博客:CloudCompare&PCL ...
- 读自动驾驶激光雷达物体检测技术(Lidar Obstacle Detection)(4):Clustering(欧式聚类)
在第(3)实现了地面点与障碍物的分离,此部分要实现的是聚类,聚类是指把不同物体的点云分别组合聚集起来, 从而能让你跟踪汽车, 行人等多个目标. 其中一种对点云数据进行分组和聚类的方法称为欧氏聚类. 欧 ...
- PCL点云库学习笔记 点云的欧式聚类
欧式聚类详解(点云数据处理) 欧式聚类是一种基于欧氏距离度量的聚类算法.基于KD-Tree的近邻查询算法是加速欧式聚类算法的重要预处理方法. KD-Tree最近邻搜索 Kd-树是K-dimension ...
- 基于Python的k均值聚类不同规格的商品名
基于Python的k均值聚类不同规格的商品名 前言 聚类的目标是使得同一簇内的点之间的距离较短,而不同簇中点之间的距离较大.以此来区分不同的群体. 本篇讲述使用k均值算法对超市购物记录集中的商品名称进 ...
- Python skimage快速图像处理(二)——Numpy速成
Python skimage快速图像处理(二)--Numpy速成 简介 Numpy索引 彩色图像 坐标约定 数组维数的顺序 时间维度 简介 图像在scikit-images中用Numpy矩阵表示.因此 ...
- pcl聚类----欧式聚类分割方法
欧式聚类分割方法 欧式聚类是一种基于欧氏距离度量的聚类算法 流程如下: 对于欧式聚类来说,距离判断准则为前文提到的欧氏距离.对于空间某点P,通过KD-Tree近邻搜索算法找到k个离p点最近的点,这些点 ...
- (MATLAB/C/Python)快速中值滤波
(MATLAB/C/Python)快速中值滤波 一.中值滤波 二.快速中值滤波 介绍 原理 优化 三.代码 MATLAB C Python 四.测试 其他 by HPC_ZY 最近一个项目中需要用到中 ...
- python新闻文本聚类_用Python实现文档聚类
在本教程中,我会利用 Python 来说明怎样聚类一系列的文档.我所演示的实例会识别出 top 100 电影的(来自 IMDB 列表)剧情简介的隐藏结构.关于这个例子的详细讨论在初始版本里.本教程包括 ...
最新文章
- Go gin使用html模板
- 忘记了root密码怎么办?
- selenium之如何使用cssSelector定位页面元素
- c语言数组与指针的基础知识,C语言学习笔记之数组与指针的关系
- nmap结果导出html,nmap的简单使用 - osc_ijgldkz9的个人空间 - OSCHINA - 中文开源技术交流社区...
- IOS学习笔记十八(copy、mutableCopy、NSCopying、NSMutableCopy、深复制、浅复制)
- excel查重_发票查重工具,不止查重这么简单,你还可以体验这些新玩法
- nacos初探--作为配置中心
- 51单片机冒泡排序_51单片机片外冒泡排序
- 软件关闭excel但是进程中还存在原因_从软件视角看波音737事故系列述评之一:软件普适化下的能力建设...
- win7键盘失灵 登陆界面键盘失效无法输入密码的解决办法
- 5g鸿蒙概念,华为5G概念机,真全面屏+鸿蒙系统,颜值再登巅峰
- Python 序列化模块(json,pickle,shelve)
- 5、提交报告获取服务、状态报告获取服务 -功能详细设计 --短信平台
- 重磅来袭,机器人四大家族财务报表大揭秘
- 和菜鸟一起学android4.0.3源码之硬件gps简单移植【转】
- 不同音乐格式之谜(wav,flac,ape,wv,tak,ogg,aac)
- 温度传感器的一些比较
- 001-三阶魔方-概述及层先法
- S@Kura的PHP进阶之路(二)