本文介绍了当我尝试使用plyfile API访问.ply文件时,为什么会得到ValueError:两个具有相同名称的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与一个需要访问.ply文件形式的点云数据并将其转换为numpy数组以运行深度学习算法的项目一起工作.当我尝试从目录访问我的.ply文件时,出现错误 "ValueError:两个具有相同名称的属性"

I am working with a project that requires accessing point cloud data in the form of .ply files and converting them into numpy arrays for running a deep learning algorithm. When I try to access my .ply files from my directory, I get the error "ValueError: two properties with same name"

以下是我的代码-

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

以下是错误(此处仅复制了相关部分)-

The following is the error (only relevant portions reproduced here) -

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 命令):

My ply file - vertices are partially reproduced (generated by pcl using pcl_pcd2ply command) :

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

推荐答案

感谢CristiFati将我指向不寻常的property list uint uchar _,该文件在.ply文件中两次出现.假定这种参数不应该出现在有效的.ply文件中. _必须用唯一的标识符名称表示一些有效的属性.不幸的是,这是pcl库中的问题.

Thanks to CristiFati for pointing me to the unusual property list uint uchar _ which was present twice in the .ply file. Supposedly, this kind of parameter was not supposed to be present in a valid .ply file. The _ had to represent some valid property with a unique identifier name. Unfortunately this is a problem in the pcl library.

我做了一个小解决方法来克服这个问题.如下:

I did a small workaround to overcome this. It is as follows :

  1. 问题在于从binary .pcdascii .ply
  2. 的直接转换
  3. 首先通过从binary .pcdascii .pcd的间接转换解决了该问题;然后是从ascii .pcd转换为ascii .ply格式的第二步.这种方法提供了正确的.ply文件,没有任何丢失的属性.
  1. The problem is with the direct conversion from binary .pcd to ascii .ply
  2. The problem was overcome by doing an indirect conversion first from binary .pcd to ascii .pcd; and then a second step of conversion from ascii .pcd to ascii .ply format. This approach gave a proper .ply file without any missing properties.

这篇关于当我尝试使用plyfile API访问.ply文件时,为什么会得到ValueError:两个具有相同名称的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 00:46