if road_cloud.compute_obb().intersects(line): AttributeError: 'numpy.ndarray' object has no attribute 'compute_obb'
时间: 2023-08-06 17:04:20 浏览: 159
非常抱歉,我的代码有误。`road_cloud`是一个numpy数组,不能直接调用Open3D的点云方法。需要先将numpy数组转为Open3D的点云对象,然后才能调用点云方法。下面是修改后的代码:
```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")
# 将道路点云转为Open3D的点云对象
cloud = o3d.geometry.PointCloud()
cloud.points = o3d.utility.Vector3dVector(road_cloud)
# 计算每个轨迹点之间的曲线距离
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 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])
```
这个代码中,我们先将`road_cloud`转为Open3D的点云对象`cloud`,然后使用`cloud.compute_obb()`来计算点云的OBB包围盒。
阅读全文