import numpy as np import open3d as o3d data = np.loadtxt('E:/radar_dataset_astyx-main/dataset_astyx_demo/radar_hires1/test01.txt', skiprows=1) point_cloud = o3d.geometry.PointCloud() point_cloud.points = o3d.utility.Vector3dVector(data[:, :3]) # 创建一个新的点云属性对象 velocity_attr = o3d.utility.DoubleVector(data[:, 3]) scatter_attr = o3d.utility.DoubleVector(data[:, 4]) # 将点云属性作为点的属性添加到点云对象中 point_cloud.point['velocity'] = o3d.utility.Vector3dVector(velocity_attr) point_cloud.point['scatter'] = o3d.utility.Vector3dVector(scatter_attr) o3d.visualization.draw_geometries([point_cloud])发生异常: RuntimeError Unable to cast Python instance to C++ type (compile in debug mode for details) File "E:\迅雷下载\serial-port-to-database-master\import open3d as o3d.py", line 14, in <module> point_cloud.point['velocity'] = o3d.utility.Vector3dVector(velocity_attr) RuntimeError: Unable to cast Python instance to C++ type (compile in debug mode for details)
时间: 2024-04-16 19:26:47 浏览: 136
非常抱歉,出现了另一个错误。在Open3D中,属性的设置需要使用`o3d.utility.VectorX`的形式,其中X是属性数据的类型。对于`Double`类型的属性数据,应使用`o3d.utility.DoubleVector`。以下是修改后的代码:
```python
import numpy as np
import open3d as o3d
data = np.loadtxt('E:/radar_dataset_astyx-main/dataset_astyx_demo/radar_hires1/test01.txt', skiprows=1)
point_cloud = o3d.geometry.PointCloud()
point_cloud.points = o3d.utility.Vector3dVector(data[:, :3])
# 将速度和散射强度信息作为点的属性
point_cloud.point['velocity'] = o3d.utility.VectorFloat(data[:, 3].tolist())
point_cloud.point['scatter'] = o3d.utility.VectorFloat(data[:, 4].tolist())
o3d.visualization.draw_geometries([point_cloud])
```
在这段代码中,我们使用`o3d.utility.VectorFloat`来设置速度和散射强度的属性数据,并将NumPy数组转换为Python列表。
对之前的错误造成的困扰再次表示抱歉。希望这次能满足你的需求!如果你还有其他问题,请随时提问。
阅读全文