我正在与一个需要访问.ply文件形式的点云数据并将其转换为numpy数组以运行深度学习算法的项目一起工作。当我尝试从目录访问我的.ply文件时,出现错误“ ValueError:两个具有相同名称的属性”
以下是我的代码-
import glob
import numpy as np
from plyfile import PlyData, PlyElement
arr = np.array([])
for filepath in glob.iglob('/content/drive/My Drive/PLY Files/*.ply'):
plyFile = PlyData.read(filepath)
plyFile.elements[0].properties
以下为错误(此处仅复制相关部分)-
ValueError Traceback (most recent call last)
<ipython-input-42-4464816991de> in <module>()
4
5 for filepath in glob.iglob('/content/drive/My Drive/PLY Files/*.ply'):
----> 6 plyFile = PlyData.read(filepath)
7 plyFile.elements[0].properties
/usr/local/lib/python3.6/dist-packages/plyfile.py in _index(self)
549 for prop in self._properties)
550 if len(self._property_lookup) != len(self._properties):
--> 551 raise ValueError("two properties with same name")
552
553 def ply_property(self, name):
ValueError: two properties with same name
我的层文件-顶点被部分复制(由pcl使用pcl_pcd2ply命令生成):
ply
format ascii 1.0
comment PCL generated
element vertex 92928
property float x
property float y
property float z
property list uint uchar _
property float intensity
property list uint uchar _
element camera 1
property float view_px
property float view_py
property float view_pz
property float x_axisx
property float x_axisy
property float x_axisz
property float y_axisx
property float y_axisy
property float y_axisz
property float z_axisx
property float z_axisy
property float z_axisz
property float focal
property float scalex
property float scaley
property float centerx
property float centery
property int viewportx
property int viewporty
property float k1
property float k2
end_header
0 0 0 4 0 0 128 63 0 12 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 4 0 0 128 63 0 12 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 4 0 0 128 63 0 12 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 4 0 0 128 63 0 12 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 4 0 0 128 63 0 12 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 4 0 0 128 63 0 12 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 4 0 0 128 63 0 12 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 4 0 0 128 63 0 12 0 0 0 0 0 0 0 0 0 0 0 0
[为了在问题的评论中重新陈述讨论,所讨论的PLY文件包含两个名为_
的属性,plyfile
不支持。不幸的是,我对pcl_pcd2ply
一点都不熟悉,所以我不知道是什么使它执行此操作,但是肯定在某个地方似乎是个错误。
这里是一个很容易处理的预处理ASCII格式PLY文件的方法,假设property list uint uchar _
是唯一可以出现的重复属性。它将出现的名称重命名为_1
,_2
等。>
awk '/^property list uint uchar _$/ {x++; $5 = $5 x} BEGIN {x = 0} // {print}' < X.ply
感谢CristiFati将我引向property list uint uchar _
文件中两次出现的异常.ply
。假设这种参数不应该出现在有效的.ply
文件中。 _
必须用唯一的标识符名称表示一些有效的属性。不幸的是,这是pcl库中的问题。