【PCL】激光雷达点云地⾯⽔平校准
激光雷达采集的数据,可能由于颠簸或者雷达安装倾斜或者地⾯本⾝是有坡度的,造成地⾯在雷达坐标系中不是⽔平的。不是⽔平的,会影响我们后续的对点云的分割分类等处理,所以校准很有必要。
校准⽅法是():⽤PCL中基于RANSAC的平⾯检测⽅法检测出平⾯,得到平⾯:ax+by+cz+d=0。对于⼀个平⾯,上式中xyz的系数,就是它的法向量。然后,雷达坐标系中的竖直向量是(0,0,1),计算出从平⾯法向量旋转到竖直向量的旋转矩阵,再把此旋转矩阵应⽤到点云,点云即可得到旋转。
⼀步⼀步来:
复仇者名字1,分割平⾯,得到平⾯的法向量:
pcl::SACSegmentation<pcl::PointXYZ> plane_g;
pcl::PointIndices::Ptr plane_inliers ( new pcl::PointIndices );
recyclerpcl::ModelCoefficients::Ptr plane_coefficients ( new pcl::ModelCoefficients );
plane_g.tOptimizeCoefficients (true);
orbiting
plane_g.tModelType ( pcl::SACMODEL_PLANE );
plane_g.tMethodType ( pcl::SAC_RANSAC );budget
plane_g.tDistanceThreshold ( 0.3 );
plane_g.tInputCloud ( cloud_in );
(*plane_inliers, *plane_coefficients);//得到平⾯系数,进⽽得到平⾯法向量
2,计算两个向量之间的旋转矩阵:
广州卡耐基>什么是soa
关于在已知两个向量坐标的情况下如何求两者的旋转矩阵的问题,可以看和。其中,会⽤到两个向量的点乘和叉乘,什么是点乘和叉乘,看。怎么实现点乘和叉乘,看⽤eigen库⾮常⽅便,都已经封装好了。
Eigen::Matrix4f CreateRotateMatrix(Vector3f before,Vector3f after)
{
buu
dj什么意思
float angle = acos(before.dot(after));
Vector3f p_rotate =ss(after);
alize();
Eigen::Matrix4f rotationMatrix = Eigen::Matrix4f::Identity();
rotationMatrix(0, 0) = cos(angle) + p_rotate[0] * p_rotate[0] * (1 - cos(angle));
rotationMatrix(0, 1) = p_rotate[0] * p_rotate[1] * (1 - cos(angle) - p_rotate[2] * sin(angle));//这⾥跟公式⽐多了⼀个括号,但是看实验结果它是对的。
rotationMatrix(0, 2) = p_rotate[1] * sin(angle) + p_rotate[0] * p_rotate[2] * (1 - cos(angle));
rotationMatrix(1, 0) = p_rotate[2] * sin(angle) + p_rotate[0] * p_rotate[1] * (1 - cos(angle));
rotationMatrix(1, 1) = cos(angle) + p_rotate[1] * p_rotate[1] * (1 - cos(angle));
rotationMatrix(1, 2) = -p_rotate[0] * sin(angle) + p_rotate[1] * p_rotate[2] * (1 - cos(angle));
rotationMatrix(2, 0) = -p_rotate[1] * sin(angle) +p_rotate[0] * p_rotate[2] * (1 - cos(angle));
rotationMatrix(2, 1) = p_rotate[0] * sin(angle) + p_rotate[1] * p_rotate[2] * (1 - cos(angle));
rotationMatrix(2, 2) = cos(angle) + p_rotate[2] * p_rotate[2] * (1 - cos(angle));
return rotationMatrix;
}
3,利⽤旋转矩阵,将点云旋转
东莞北大青鸟
pcl::transformPointCloud(*cloud_in, *cloud_final, rotation);
效果演⽰:
绿的是原始点云,⽩的是校准后的点云。
decision making