Open3D
Open3D copied to clipboard
[Bug] 3D Bounding Box Improper Rotation Matrices
Checklist
- [X] I have searched for similar issues.
- [X] For Python issues, I have tested with the latest development wheel.
- [X] I have checked the release documentation and the latest documentation (for
masterbranch).
My Observation
Using : open3d 0.15.2
TLDR; Orientated Bounding Boxes are inconsistent:
- Mix between proper and improper Rotation matrices
- Mix of reflections in improper Rotation matrices
- Incompatible with other frameworks.
Hello, I am creating bounding boxes from pointcloud clusters. I am using orientated bounding boxes. Rotating the bounding box by its transposed Rotation matrix will align it with the axes (I know allignedbboxes exist, this is just to describe the issue). This works correctly if I stick with open3d.
However other packages (scipy, spatialmath) have issues with the Open3D rotation matrix. Converting to quaternion or vectors and reversing into rotation matrix causes issues and the rotations are incorrect. I have observed that the determinant of the Open3D Rotation matrices are mixed between -1 and 1. This inconsistency is incompatible with all frameworks I have tried (scipy, pytransform3d, spatialmath, etc.) (Picture 1 vs Picture 2. This makes further processing challenging/impossible.
bbox = o3d.geometry.OrientedBoundingBox.create_from_points(points=pc.points) r = R.from_matrix(np.array(bbox.R)) bbox.rotate(np.transpose(r.as_matrix()))
This is what it looks like if I transpose the open3d rotation matrix with scipy.

This is what it looks like if I transpose the incorrect Open3D rotation matrices (expected result)

I have found a workaround : credit, however, this shows the next issue. See the box of the small window and compare it to the last picture. Within the improper rotation matrices, the reflections are inconsistent. Some aligned boxes "fell over" on their side instead of remaining upright. Others align correctly.

Possibly related issue : https://github.com/isl-org/Open3D/issues/2892 However, I am not using any values except x, y, z
@benjaminum Any suggestions as you have worked on this in a past issue before?
This might not be a bug. I found that the order of rotation in Open3D and scipy seems to be different. Below is the code snippet to verify this:
import numpy as np
import open3d as o3d
from scipy.spatial.transform import Rotation
# Rotate 20, 30, 40 degrees along x, y, z axis in Open3D
R_o3d = o3d.geometry.OrientedBoundingBox.get_rotation_matrix_from_xyz(np.array([20, 30, 40])/180*np.pi)
print(R_o3d)
# To generate the exact rotation matrix, we have to do in the reverser order in scipy
R_scipy = Rotation.from_euler('zyx', [40, 30, 20], degrees=True)
print(R_scipy.as_matrix())
# Convert rotation matrix in open3d to angles in scipy
r = Rotation.from_matrix(R_o3d)
angles = r.as_euler('zyx')
print(angles/np.pi*180)
Hope the provided info is useful for anyone comes across this issue.