0
votes

I am using the Axis Aligned bounding box in PCL after clustering the clouds. I use it vehicle detection and tracking application. Is there any way to rotate the axis aligned box according to the cloud as i need the yaw information from the box.

Thank you

using an OOB doesn't generate a box representative of the vehicle click here for ref. image

2

2 Answers

2
votes

Using pcl::MomentOfInertiaEstimation

Official PCL tutorial on: Moment of inertia and eccentricity based descriptors.

If you're interested in yaw, then you need to use the OBB (oriented bounding box), rather than the AABB (axis aligned bounding box). AABB is, as the name suggests, aligned with the axis, and is basically equivalent to taking the min/max of each coordinate. OBB in PCL is based on the eigen vectors of the Principal Component Analysis (directions of maximum variance).

Code (from the tutorial) for the extraction of the OBB:

pcl::MomentOfInertiaEstimation <pcl::PointXYZ> feature_extractor;
feature_extractor.setInputCloud (cloud);
feature_extractor.compute ();

pcl::PointXYZ min_point_OBB;
pcl::PointXYZ max_point_OBB;
pcl::PointXYZ position_OBB;
Eigen::Matrix3f rotational_matrix_OBB;
Eigen::Vector3f major_vector, middle_vector, minor_vector;
Eigen::Vector3f mass_center;

feature_extractor.getOBB (min_point_OBB, max_point_OBB, position_OBB, rotational_matrix_OBB);
feature_extractor.getEigenVectors (major_vector, middle_vector, minor_vector);
feature_extractor.getMassCenter (mass_center);

From the documentation:

Note that in order to get the OBB, each vertex of the given AABB (specified with min_point and max_point) must be rotated with the given rotational matrix (rotation transform) and then positioned.

So to get the final OBB - The coordinates:

Eigen::Vector3f p1 (min_point_OBB.x, min_point_OBB.y, min_point_OBB.z);
Eigen::Vector3f p2 (min_point_OBB.x, min_point_OBB.y, max_point_OBB.z);
Eigen::Vector3f p3 (max_point_OBB.x, min_point_OBB.y, max_point_OBB.z);
Eigen::Vector3f p4 (max_point_OBB.x, min_point_OBB.y, min_point_OBB.z);
Eigen::Vector3f p5 (min_point_OBB.x, max_point_OBB.y, min_point_OBB.z);
Eigen::Vector3f p6 (min_point_OBB.x, max_point_OBB.y, max_point_OBB.z);
Eigen::Vector3f p7 (max_point_OBB.x, max_point_OBB.y, max_point_OBB.z);
Eigen::Vector3f p8 (max_point_OBB.x, max_point_OBB.y, min_point_OBB.z);

p1 = rotational_matrix_OBB * p1 + position;
p2 = rotational_matrix_OBB * p2 + position;
p3 = rotational_matrix_OBB * p3 + position;
p4 = rotational_matrix_OBB * p4 + position;
p5 = rotational_matrix_OBB * p5 + position;
p6 = rotational_matrix_OBB * p6 + position;
p7 = rotational_matrix_OBB * p7 + position;
p8 = rotational_matrix_OBB * p8 + position;

Using pcl::pca

PCL Documentation

Tutorial at codextechnicanum.blogspot.co.il

If you're just interested in the direction vector of the vehicle, then assuming it is along the major eigen vector:

pcl::PCA<pcl::PointXYZ> pca(cloud, true);
Eigen::Matrix3f eigen_vector = pca.getEigenVectors(); // returns a matrix where the columns are the axis of your bounding box    
Eigen::Vector3f direction = eigen_vector.col(0);
0
votes

Found a solution for this. I used OOBB with restricting the rotation only in z axis, so the other two axis rotation is not considered

Eigen::Vector3f ea = rotational_matrix_OBB.eulerAngles(0, 0, yaw);