我正在尝试从点云获取OBB,并且我使用pcl :: MomentOfInertiaEstimation方法获得了正确的结果。我想使用CropBox从OBB中提取点,但是我得到的点比原点少得多云,也许我的旋转矢量有问题:v,我不太确定。谁能帮我?
struct BoundingBox{
pcl::PointXYZ min_point_OBB;
pcl::PointXYZ max_point_OBB;
pcl::PointXYZ position_OBB;
Eigen::Matrix3f rotational_matrix_OBB;
pcl::PointXYZ center;
pcl::PointXYZ x_axis;
pcl::PointXYZ y_axis;
pcl::PointXYZ z_axis;
};
BoundingBox getOBB(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud,BoundingBox OBB )
{
pcl::MomentOfInertiaEstimation <pcl::PointXYZ> feature_extractor;
feature_extractor.setInputCloud (cloud);
feature_extractor.compute ();
feature_extractor.getOBB (OBB.min_point_OBB, OBB.max_point_OBB, OBB.position_OBB, OBB.rotational_matrix_OBB);
return OBB;
}
int main(void){
BoundingBox OBB;
OBB=getOBB(Npoints,OBB); //Npoints is a part of the whole cloud
Eigen::Quaternionf quat (OBB.rotational_matrix_OBB);
Eigen::Vector3f position (OBB.position_OBB.x, OBB.position_OBB.y, OBB.position_OBB.z);
pcl::visualization::PCLVisualizer viewer;
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> points_color_handler (cloud, 255, 255, 255);
viewer.addCube (position, quat, OBB.max_point_OBB.x - OBB.min_point_OBB.x, OBB.max_point_OBB.y - OBB.min_point_OBB.y, OBB.max_point_OBB.z - OBB.min_point_OBB.z,"OBB");
viewer.setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_REPRESENTATION, pcl::visualization::PCL_VISUALIZER_REPRESENTATION_WIREFRAME,"OBB");
////////////////above result is correct////////////////////
Eigen::Vector4f max_point_OBB(OBB.max_point_OBB.x,OBB.max_point_OBB.y,OBB.max_point_OBB.z,1.0);
Eigen::Vector4f min_point_OBB(OBB.min_point_OBB.x,OBB.min_point_OBB.y,OBB.min_point_OBB.z,1.0);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloudOut (new pcl::PointCloud<pcl::PointXYZ>);
pcl::CropBox<pcl::PointXYZ> boxfilter;
boxfilter.setMax(max_point_OBB);
boxfilter.setMin(min_point_OBB);
Eigen::Vector3f v = quat.vec();
boxfilter.setTranslation(position);
boxfilter.setRotation(v);
boxfilter.setInputCloud(cloud);
boxfilter.filter (*cloudOut);
/////////cloulOut includes much less points than Npoints/////////
寻找答案!