在使用Open3D中用于生成旋转矩阵的函数
def creat_c2w(path, point, ID):
qvec, t = image_data_loader(path, ID)
extrinsics = point.get_rotation_matrix_from_quaternion(qvec)
c2w = np.matrix(extrinsics)
c2w = np.column_stack((c2w, t))
c2w = np.row_stack((c2w,[0,0,0,1]))
return c2w
然而系统却报错
AttributeError: 'open3d.open3d.geometry.PointCloud' object has no attribute 'get_rotation_matrix_from_quaternion'
通过查阅相关资料发现可能存在因为版本更迭,模型位置发生变动的情况,我安装的是open3d 0.17.0、open3d-python 0.7.0.0。我便对照open3d官方文档
open3d官方文档
发现函数get_rotation_matrix_from_quaternion在geometry里面,然而我在geometry里面却没有发现这个函数
open3d.geometry模块中没有get_rotation_matrix_from_quaternion函数,这个函数在新的版本中被移除或重命名了
尝试更新到最新版
尝试在Open3D GitHub存储库中查找该函数,或者在API文档查找类似的替代函数
基于最新版ChatGPT4的回答,望采纳!!!有其他问题也可以询问我哦、”(最新版更智能,功能更加强大)
从你的描述来看,你的问题主要是在Open3D 0.17.0版本中找不到get_rotation_matrix_from_quaternion
函数。实际上,这个函数并不属于PointCloud
类,而是属于open3d.geometry
模块中的一个独立函数。在Open3D的新版本(0.10.0及更高版本)中,这个函数已经被移动到了open3d.core
模块,并且更名为rotation_matrix_from_quaternion
。你可以按照以下方式使用这个函数:
首先,确保你已经安装了最新版本的Open3D库。可以使用以下命令进行安装:
pip install open3d
然后,你可以修改creat_c2w
函数,使用open3d.core
模块中的rotation_matrix_from_quaternion
函数来创建旋转矩阵:
import numpy as np
import open3d as o3d
from open3d.core import Tensor
def creat_c2w(path, point, ID):
qvec, t = image_data_loader(path, ID)
# 使用新的函数名,并从open3d.core模块中调用
extrinsics = o3d.core.rotation_matrix_from_quaternion(Tensor(qvec, dtype=o3d.core.Dtype.Float32))
c2w = np.matrix(extrinsics.cpu().numpy()) # 将旋转矩阵转换为numpy矩阵
c2w = np.column_stack((c2w, t))
c2w = np.row_stack((c2w, [0, 0, 0, 1]))
return c2w
请注意,你需要将四元数转换为open3d.core.Tensor
类型,并确保其数据类型为open3d.core.Dtype.Float32
。在使用旋转矩阵之前,还需要将其从open3d.core.Tensor
类型转换回numpy
矩阵。
以下答案由GPT-3.5大模型与博主波罗歌共同编写:
这可能是由于您正在运行较早的open3d版本而引起的。 get_rotation_matrix_from_quaternion
函数在open3d版本0.9.0及以后的版本中才被引入。这意味着该函数不适用于open3d 0.17.0和open3d-python 0.7.0.0。您可以考虑更新open3d版本或使用其他适当的函数。
对于旧版open3d,可以使用旋转矩阵和四元数之间的转换函数,如下所示:
from scipy.spatial.transform import Rotation as R
qvec, t = image_data_loader(path, ID)
r = R.from_quat(qvec)
extrinsics = r.as_matrix()
c2w = np.matrix(extrinsics)
c2w = np.column_stack((c2w, t))
c2w = np.row_stack((c2w,[0,0,0,1]))
return c2w
其中from_quat
函数将四元数转换为旋转矩阵,as_matrix
函数返回旋转矩阵。您可以将其嵌入到您的代码中并根据需要进行更改。
如果我的回答解决了您的问题,请采纳!
就像你说的,这种问题一般都是版本的问题,最好的解决方法就是查阅对应版本的官方API文档,既然你说get_rotation_matrix_from_quaternion方法在geometry下面,那么你的调用方法的形式应该是类似这样的:
open3d.geometry.get_rotation_matrix_from_quaternion(......)
其次,如果你在geometry中没有找到get_rotation_matrix_from_quaternion,说明你的open3d-python版本不对,请更新下这个库。
问题分析: