AttributeError: 'open3d.cpu.pybind.geometry.PointCloud' object has no attribute 'compute_point_cloud_normals'
时间: 2023-10-30 11:57:24 浏览: 146
这个错误是因为属性名拼写错误或者方法名拼写错误导致的。在这个错误中,你正在尝试调用一个名为`compute_point_cloud_normals`的方法,但是点云对象没有这个方法,因此 Python 引发了 AttributeError。
请检查你的代码,确保正确地调用了方法并拼写了正确的方法名。你可以查看文档或参考其他示例代码,以确保你正在使用正确的方法名和拼写。
相关问题
AttributeError: 'open3d.open3d_pybind.geometry.PointCloud' object has no attribute 'triangulate
很抱歉,我之前的回答有误。Open3D的PointCloud对象确实没有`triangulate`方法。为了将点云三角化,可以使用以下代码:
```python
import rospy
import moveit_msgs.msg as moveit_msgs
import open3d as o3d
import numpy as np
def point_cloud_to_scene(point_cloud_topic, camera_frame_id, scene_publisher):
# Subscribe to point cloud topic
point_cloud = rospy.wait_for_message(point_cloud_topic, sensor_msgs.msg.PointCloud2)
# Convert point cloud to numpy array
points = np.array(list(pc2.read_points(point_cloud, skip_nans=True)))
# Convert numpy array to Open3D point cloud
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(points)
# Triangulate point cloud
tri = o3d.geometry.TriangleMesh.create_from_point_cloud_alpha_shape(pcd, alpha=0.03)
# Convert Open3D triangle mesh to MoveIt scene
vertices = np.asarray(tri.vertices)
triangles = np.asarray(tri.triangles)
scene_msg = moveit_msgs.PlanningScene()
scene_msg.is_diff = True
object_msg = moveit_msgs.PlanningSceneWorld()
object_msg.collision_objects.append(moveit_msgs.CollisionObject())
object_msg.collision_objects[0].id = "point_cloud"
object_msg.collision_objects[0].header.frame_id = camera_frame_id
object_msg.collision_objects[0].meshes.append(moveit_msgs.Mesh())
object_msg.collision_objects[0].meshes[0].vertices = [moveit_msgs.Vertex(x=vertices[i][0], y=vertices[i][1], z=vertices[i][2]) for i in range(vertices.shape[0])]
object_msg.collision_objects[0].meshes[0].triangles = [moveit_msgs.Triangle(mesh.vertices[i][0], mesh.vertices[i][1], mesh.vertices[i][2]) for i in range(triangles.shape[0])]
scene_msg.world.collision_objects = object_msg.collision_objects
scene_publisher.publish(scene_msg)
```
这个函数会将点云转换为Open3D的PointCloud对象,然后使用`create_from_point_cloud_alpha_shape`函数进行三角化,生成Open3D的TriangleMesh对象。接下来,将TriangleMesh对象转换为MoveIt环境scene,并发布到MoveIt Planning Scene的话题上。
请注意,这个函数需要安装Open3D库。
发生异常: AttributeError 'open3d.cpu.pybind.geometry.PointCloud' object has no attribute 'point_attr' File "E:\迅雷下载\serial-port-to-database-master\import open3d as o3d.py", line 10, in <module> point_cloud.point_attr['velocity'] = o3d.utility.DoubleVector(data[:, 4]) AttributeError: 'open3d.cpu.pybind.geometry.PointCloud' object has no attribute 'point_attr'
非常抱歉,我之前提供的代码有误。在Open3D的最新版本中,`PointCloud`对象没有名为`point_attr`的属性。请使用以下代码进行修改:
```python
import numpy as np
import open3d as o3d
data = np.loadtxt('E:/radar_dataset_astyx-main/dataset_astyx_demo/radar_hires1/000000.txt', skiprows=1)
point_cloud = o3d.geometry.PointCloud()
point_cloud.points = o3d.utility.Vector3dVector(data[:, :3])
# 创建一个新的点云属性对象
velocity_attr = o3d.geometry.PointAttribute()
scatter_attr = o3d.geometry.PointAttribute()
# 设置点云属性的名称和数据
velocity_attr.name = "velocity"
velocity_attr.data = o3d.utility.DoubleVector(data[:, 3])
scatter_attr.name = "scatter"
scatter_attr.data = o3d.utility.DoubleVector(data[:, 4])
# 将点云属性添加到点云对象中
point_cloud.point_attributes.append(velocity_attr)
point_cloud.point_attributes.append(scatter_attr)
o3d.visualization.draw_geometries([point_cloud])
```
在这段代码中,我们创建了两个新的点云属性对象`velocity_attr`和`scatter_attr`,并设置了它们的名称和数据。然后,我们使用`point_cloud.point_attributes.append()`将这两个属性对象添加到点云对象中。
再次对之前的错误造成的困扰表示抱歉。希望这次能满足你的需求!如果你还有其他问题,请随时提问。
阅读全文