line = o3d.geometry.LineSet.create_from_numpy_array(np.array([viewpoint, endpoint]).reshape(-1, 3)) AttributeError: type object 'open3d.cpu.pybind.geometry.LineSet' has no attribute 'create_from_numpy_array'
时间: 2024-03-27 20:41:42 浏览: 100
disk_get_inf.zip_Disk.inf_disk_get_inf
非常抱歉,Open3D的API在更新后发生了变化,`create_from_numpy_array`这个方法已经被移除了。下面是修改后的代码:
```python
import numpy as np
import open3d as o3d
# 读取道路点云txt文件和gps轨迹文件
road_cloud = np.loadtxt("road_cloud.txt")
gps_track = np.loadtxt("gps_track.txt")
# 计算每个轨迹点之间的曲线距离
distances = []
for i in range(len(gps_track)-1):
p1 = gps_track[i]
p2 = gps_track[i+1]
dist = np.sqrt(np.sum((p2-p1)**2))
distances.append(dist)
# 遍历每个轨迹点,检测视点与下一个轨迹点之间是否有障碍物
for i in range(len(gps_track)-1):
# 将当前轨迹点作为视点
viewpoint = gps_track[i]
print("Viewpoint:", viewpoint)
# 找到下一个有障碍物的轨迹点
next_obstacle_index = i+1
for j in range(i+1, len(gps_track)):
endpoint = gps_track[j]
line = o3d.geometry.LineSet()
line.points = o3d.utility.Vector3dVector([viewpoint, endpoint])
line.lines = o3d.utility.Vector2iVector([[0, 1]])
if road_cloud.compute_obb().intersects(line):
break
else:
next_obstacle_index = j
# 计算视点与下一个有障碍物的轨迹点之间的曲线距离
distance = np.sum(distances[i:next_obstacle_index])
print("Distance to next obstacle:", distance)
# 可视化结果
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(road_cloud)
o3d.visualization.draw_geometries([pcd])
```
这个代码中我们使用了`compute_obb`方法来计算点云的OBB包围盒,然后使用包围盒的`intersects`方法来检测障碍物。这样就可以避免使用已经被移除的`create_from_numpy_array`方法了。
阅读全文