Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

[Bug] 3D Bounding Box Improper Rotation Matrices

Open L-Reichardt opened this issue 3 years ago • 3 comments
trafficstars

Checklist

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. scipy

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

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.

1

L-Reichardt avatar Aug 01 '22 13:08 L-Reichardt

L-Reichardt avatar Aug 01 '22 14:08 L-Reichardt

Possibly related issue : https://github.com/isl-org/Open3D/issues/2892 However, I am not using any values except x, y, z

L-Reichardt avatar Aug 01 '22 14:08 L-Reichardt

@benjaminum Any suggestions as you have worked on this in a past issue before?

L-Reichardt avatar Aug 03 '22 08:08 L-Reichardt

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.

lxfhfut avatar Dec 12 '22 00:12 lxfhfut