导入相机至MeshLab时位置错位问题求助
相机变换矩阵在Open3D与MeshLab间的导入错位问题
我通过相机对齐得到4x4变换矩阵形式的相机位姿信息,在Open3D中可视化完全正常:物体位于相机中心,RGB轴对应场景原点,代码和显示效果都符合预期。
但将这些相机导入MeshLab时,我编写脚本生成了.mlp项目文件,打开后相机位置出现错位——相机沿Z轴镜像且旋转了180度。
最小复现步骤
可通过以下步骤复现:
git clone https://github.com/flolu/meshlab-camera-transformationcd meshlab-camera-transformationconda env create -n meshlab-camera-transformation -f conda.yml(耗时较长)conda activate meshlab-camera-transformation
- 执行
python visualize_cameras.py查看Open3D中的正常场景 - 执行
python main.py生成MeshLab项目文件
在MeshLab中查看相机的操作:
- 打开MeshLab
- 文件➝打开项目...➝选择
project.mlp - 渲染➝显示相机
- 在右下角“显示相机”选项中,将“相机缩放方式”设为“固定系数”,输入
0.005作为缩放系数 - 滚动缩放视图
- 渲染➝显示轴
已尝试的方案
我尝试对相机变换矩阵做反向变换,代码如下:
for transformation_matrix in camera_transformation_matrices: # flip z value transformation_matrix[2, 3] *= -1 # swap y and z rotation swap_y_and_z = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) transformation_matrix[:3, :3] = np.matmul( swap_y_and_z, transformation_matrix[:3, :3]) # rotate transformation_matrix 90 degrees about y axis of the camera rotate_90_around_y_axis = np.array([[math.cos(-math.pi/2), 0, math.sin(-math.pi/2)], [0, 1, 0], [-math.sin(-math.pi/2), 0, math.cos(-math.pi/2)]]) T = np.eye(4) T[:3, :3] = rotate_90_around_y_axis T[:3, 3] = transformation_matrix[:3, 3] - \ np.matmul(rotate_90_around_y_axis, transformation_matrix[:3, 3]) transformation_matrix[:4, :4] = np.matmul(T, transformation_matrix)
调整后MeshLab里的相机位置看似正常,但切换到“显示当前光栅模式”查看相机视角时,画面和网格完全不对齐——多数视角看不到网格,而相机本应朝向网格。可执行python failed_try.py生成project_failed_try.mlp测试该情况。
问题
- 为什么会出现相机错位的情况?
- 如何解决视角未对齐的问题?
内容的提问来源于stack exchange,提问作者Florian Ludewig
相关产品推荐
相关产品推荐

