- opencv 中 camera calibration 原理
k1, k2, k3, k4, k5, k6
径向畸变 radial distortion coefficients. p1, p2
切向畸变 tangential distortion coefficients. 更高阶不考虑- 畸变校正相当于在相机坐标系
Z=1
处进行某种2维映射
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/983e028f23d061d7772844abb5c9c229.png)
inline Eigen::Vector2i reproject(Eigen::Vector3d point, Image image, Camera camera) {
Eigen::Vector4d point_homo = { point[0], point[1], point[2], 1 };
Eigen::Matrix<double, 3, 4> RT;
RT.leftCols<3>() = image.R;
RT.rightCols<1>() = -image.R*image.C;
Eigen::Vector3d point_cam = RT * point_homo;
double u = point_cam.x() / point_cam.z();
double v = point_cam.y() / point_cam.z();
Eigen::Vector2i reprojected;
if (camera.model_id == "FULL_OPENCV") {
double k1 = camera.params[4];
double k2 = camera.params[5];
double p1 = camera.params[6];
double p2 = camera.params[7];
double k3 = camera.params[8];
double k4 = camera.params[9];
double k5 = camera.params[10];
double k6 = camera.params[11];
double u2 = u * u;
double uv = u * v;
double v2 = v * v;
double r2 = u2 + v2;
double r4 = r2 * r2;
double r6 = r4 * r2;
double radial = (1 + k1 * r2 + k2 * r4 + k3 * r6) / (1 + k4 * r2 + k5 * r4 + k6 * r6);
u = u * radial + 2 * p1 * uv + p2 * (r2 + 2 * u2);
v = v * radial + 2 * p2 * uv + p1 * (r2 + 2 * v2);
double fx = camera.params[0];
double fy = camera.params[1];
double cx = camera.params[2];
double cy = camera.params[3];
reprojected[0] = std::ceil(fx*u + cx);
reprojected[1] = std::ceil(fy*v + cy);
}
if (camera.model_id == "SIMPLE_PINHOLE") {
double f = camera.params[0];
double cx = camera.params[1];
double cy = camera.params[2];
reprojected[0] = std::ceil(f * u + cx);
reprojected[1] = std::ceil(f * v + cy);
}
return reprojected;
}