86 const Eigen::VectorXd & parameters)
104 const Eigen::Vector2d & pointUndistorted,
105 Eigen::Vector2d * pointDistorted)
const
108 const double u0 = pointUndistorted[0];
109 const double u1 = pointUndistorted[1];
110 const double mx_u = u0 * u0;
111 const double my_u = u1 * u1;
112 const double rho_u = mx_u + my_u;
115 const double mxy_u = u0 * u1;
116 const double rad_dist_u = (1.0 + ((
k3_ * rho_u +
k2_) * rho_u +
k1_) * rho_u)
117 / (1.0 + ((
k6_ * rho_u +
k5_) * rho_u +
k4_) * rho_u);
118 (*pointDistorted)[0] = u0 * rad_dist_u + 2.0 *
p1_ * mxy_u
119 +
p2_ * (rho_u + 2.0 * mx_u);
120 (*pointDistorted)[1] = u1 * rad_dist_u + 2.0 *
p2_ * mxy_u
121 +
p1_ * (rho_u + 2.0 * my_u);
126 const Eigen::Vector2d & pointUndistorted, Eigen::Vector2d * pointDistorted,
127 Eigen::Matrix2d * pointJacobian, Eigen::Matrix2Xd * parameterJacobian)
const
130 const double u0 = pointUndistorted[0];
131 const double u1 = pointUndistorted[1];
132 const double mx_u = u0 * u0;
133 const double my_u = u1 * u1;
134 const double mxy_u = u0 * u1;
135 const double rho_u = mx_u + my_u;
140 const double c = rho_u*(
k4_+rho_u*(
k5_+
k6_*rho_u))+1.0;
141 const double c2 = c*c;
143 const double rad_dist_u = (1.0 + ((
k3_ * rho_u +
k2_) * rho_u +
k1_) * rho_u)
144 / (1.0 + ((
k6_ * rho_u +
k5_) * rho_u +
k4_) * rho_u);
145 (*pointDistorted)[0] = u0 * rad_dist_u + 2.0 *
p1_ * mxy_u
146 +
p2_ * (rho_u + 2.0 * mx_u);
147 (*pointDistorted)[1] = u1 * rad_dist_u + 2.0 *
p2_ * mxy_u
148 +
p1_ * (rho_u + 2.0 * my_u);
151 Eigen::Matrix2d & J = *pointJacobian;
153 J(0,1) =
p1_*u0*2.0+
p2_*u1*2.0+(u0*(rho_u*(u1*(
k2_+
k3_*rho_u)*2.0+
k3_*u1*rho_u*2.0)+u1*(
k1_+rho_u*(
k2_+
k3_*rho_u))*2.0))/(rho_u*(
k4_+rho_u*(
k5_+
k6_*rho_u))+1.0)-u0*(rho_u*(u1*(
k5_+
k6_*rho_u)*2.0+
k6_*u1*rho_u*2.0)+u1*(
k4_+rho_u*(
k5_+
k6_*rho_u))*2.0)*(rho_u*(
k1_+rho_u*(
k2_+
k3_*rho_u))+1.0)*1.0/c2;
154 J(1,0) =
p1_*u0*2.0+
p2_*u1*2.0+(u1*(rho_u*(u0*(
k2_+
k3_*rho_u)*2.0+
k3_*u0*rho_u*2.0)+u0*(
k1_+rho_u*(
k2_+
k3_*rho_u))*2.0))/(rho_u*(
k4_+rho_u*(
k5_+
k6_*rho_u))+1.0)-u1*(rho_u*(u0*(
k5_+
k6_*rho_u)*2.0+
k6_*u0*rho_u*2.0)+u0*(
k4_+rho_u*(
k5_+
k6_*rho_u))*2.0)*(rho_u*(
k1_+rho_u*(
k2_+
k3_*rho_u))+1.0)*1.0/c2;
157 if (parameterJacobian) {
159 const double rho_u2 = rho_u*rho_u;
160 const double rho_u3 = rho_u*rho_u2;
161 Eigen::Matrix2Xd & Jp = *parameterJacobian;
163 Jp(0,0) = (u0*rho_u)/(rho_u*(
k4_+rho_u*(
k5_+
k6_*rho_u))+1.0);
164 Jp(0,1) = (u0*rho_u2)/(rho_u*(
k4_+rho_u*(
k5_+
k6_*rho_u))+1.0);
166 Jp(0,3) = (u0*u0)*3.0+u1*u1;
167 Jp(0,4) = (u0*rho_u3)/(rho_u*(
k4_+rho_u*(
k5_+
k6_*rho_u))+1.0);
168 Jp(0,5) = -u0*rho_u*(rho_u*(
k1_+rho_u*(
k2_+
k3_*rho_u))+1.0)*1.0/c2;
169 Jp(0,6) = -u0*rho_u2*(rho_u*(
k1_+rho_u*(
k2_+
k3_*rho_u))+1.0)*1.0/c2;
170 Jp(0,7) = -u0*rho_u3*(rho_u*(
k1_+rho_u*(
k2_+
k3_*rho_u))+1.0)*1.0/c2;
171 Jp(1,0) = (u1*rho_u)/(rho_u*(
k4_+rho_u*(
k5_+
k6_*rho_u))+1.0);
172 Jp(1,1) = (u1*rho_u2)/(rho_u*(
k4_+rho_u*(
k5_+
k6_*rho_u))+1.0);
173 Jp(1,2) = u0*u0+(u1*u1)*3.0;
175 Jp(1,4) = (u1*rho_u3)/(rho_u*(
k4_+rho_u*(
k5_+
k6_*rho_u))+1.0);
176 Jp(1,5) = -u1*rho_u*(rho_u*(
k1_+rho_u*(
k2_+
k3_*rho_u))+1.0)*1.0/c2;
177 Jp(1,6) = -u1*rho_u2*(rho_u*(
k1_+rho_u*(
k2_+
k3_*rho_u))+1.0)*1.0/c2;
178 Jp(1,7) = -u1*rho_u3*(rho_u*(
k1_+rho_u*(
k2_+
k3_*rho_u))+1.0)*1.0/c2;
184 const Eigen::Vector2d & pointUndistorted,
185 const Eigen::VectorXd & parameters, Eigen::Vector2d * pointDistorted,
186 Eigen::Matrix2d * pointJacobian, Eigen::Matrix2Xd * parameterJacobian)
const
188 const double k1 = parameters[0];
189 const double k2 = parameters[1];
190 const double p1 = parameters[2];
191 const double p2 = parameters[3];
192 const double k3 = parameters[4];
193 const double k4 = parameters[5];
194 const double k5 = parameters[6];
195 const double k6 = parameters[7];
197 const double u0 = pointUndistorted[0];
198 const double u1 = pointUndistorted[1];
199 const double mx_u = u0 * u0;
200 const double my_u = u1 * u1;
201 const double mxy_u = u0 * u1;
202 const double rho_u = mx_u + my_u;
207 const double c = rho_u*(k4+rho_u*(k5+k6*rho_u))+1.0;
208 const double c2 = c*c;
210 const double rad_dist_u = (1.0 + ((k3 * rho_u + k2) * rho_u + k1) * rho_u)
211 / (1.0 + ((k6 * rho_u + k5) * rho_u + k4) * rho_u);
212 (*pointDistorted)[0] = u0 * rad_dist_u + 2.0 * p1 * mxy_u
213 + p2 * (rho_u + 2.0 * mx_u);
214 (*pointDistorted)[1] = u1 * rad_dist_u + 2.0 * p2 * mxy_u
215 + p1 * (rho_u + 2.0 * my_u);
218 Eigen::Matrix2d & J = *pointJacobian;
219 J(0,0) = p1*u1*2.0+p2*u0*6.0+(rho_u*(k1+rho_u*(k2+k3*rho_u))+1.0)/(rho_u*(k4+rho_u*(k5+k6*rho_u))+1.0)+(u0*(rho_u*(u0*(k2+k3*rho_u)*2.0+k3*u0*rho_u*2.0)+u0*(k1+rho_u*(k2+k3*rho_u))*2.0))/(rho_u*(k4+rho_u*(k5+k6*rho_u))+1.0)-u0*(rho_u*(u0*(k5+k6*rho_u)*2.0+k6*u0*rho_u*2.0)+u0*(k4+rho_u*(k5+k6*rho_u))*2.0)*(rho_u*(k1+rho_u*(k2+k3*rho_u))+1.0)*1.0/c2;
220 J(0,1) = p1*u0*2.0+p2*u1*2.0+(u0*(rho_u*(u1*(k2+k3*rho_u)*2.0+k3*u1*rho_u*2.0)+u1*(k1+rho_u*(k2+k3*rho_u))*2.0))/(rho_u*(k4+rho_u*(k5+k6*rho_u))+1.0)-u0*(rho_u*(u1*(k5+k6*rho_u)*2.0+k6*u1*rho_u*2.0)+u1*(k4+rho_u*(k5+k6*rho_u))*2.0)*(rho_u*(k1+rho_u*(k2+k3*rho_u))+1.0)*1.0/c2;
221 J(1,0) = p1*u0*2.0+p2*u1*2.0+(u1*(rho_u*(u0*(k2+k3*rho_u)*2.0+k3*u0*rho_u*2.0)+u0*(k1+rho_u*(k2+k3*rho_u))*2.0))/(rho_u*(k4+rho_u*(k5+k6*rho_u))+1.0)-u1*(rho_u*(u0*(k5+k6*rho_u)*2.0+k6*u0*rho_u*2.0)+u0*(k4+rho_u*(k5+k6*rho_u))*2.0)*(rho_u*(k1+rho_u*(k2+k3*rho_u))+1.0)*1.0/c2;
222 J(1,1) = p1*u1*6.0+p2*u0*2.0+(rho_u*(k1+rho_u*(k2+k3*rho_u))+1.0)/(rho_u*(k4+rho_u*(k5+k6*rho_u))+1.0)+(u1*(rho_u*(u1*(k2+k3*rho_u)*2.0+k3*u1*rho_u*2.0)+u1*(k1+rho_u*(k2+k3*rho_u))*2.0))/(rho_u*(k4+rho_u*(k5+k6*rho_u))+1.0)-u1*(rho_u*(u1*(k5+k6*rho_u)*2.0+k6*u1*rho_u*2.0)+u1*(k4+rho_u*(k5+k6*rho_u))*2.0)*(rho_u*(k1+rho_u*(k2+k3*rho_u))+1.0)*1.0/c2;
224 if (parameterJacobian) {
226 const double rho_u2 = rho_u*rho_u;
227 const double rho_u3 = rho_u*rho_u2;
228 Eigen::Matrix2Xd & Jp = *parameterJacobian;
230 Jp(0,0) = (u0*rho_u)/(rho_u*(k4+rho_u*(k5+k6*rho_u))+1.0);
231 Jp(0,1) = (u0*rho_u2)/(rho_u*(k4+rho_u*(k5+k6*rho_u))+1.0);
233 Jp(0,3) = (u0*u0)*3.0+u1*u1;
234 Jp(0,4) = (u0*rho_u3)/(rho_u*(k4+rho_u*(k5+k6*rho_u))+1.0);
235 Jp(0,5) = -u0*rho_u*(rho_u*(k1+rho_u*(k2+k3*rho_u))+1.0)*1.0/c2;
236 Jp(0,6) = -u0*rho_u2*(rho_u*(k1+rho_u*(k2+k3*rho_u))+1.0)*1.0/c2;
237 Jp(0,7) = -u0*rho_u3*(rho_u*(k1+rho_u*(k2+k3*rho_u))+1.0)*1.0/c2;
238 Jp(1,0) = (u1*rho_u)/(rho_u*(k4+rho_u*(k5+k6*rho_u))+1.0);
239 Jp(1,1) = (u1*rho_u2)/(rho_u*(k4+rho_u*(k5+k6*rho_u))+1.0);
240 Jp(1,2) = u0*u0+(u1*u1)*3.0;
242 Jp(1,4) = (u1*rho_u3)/(rho_u*(k4+rho_u*(k5+k6*rho_u))+1.0);
243 Jp(1,5) = -u1*rho_u*(rho_u*(k1+rho_u*(k2+k3*rho_u))+1.0)*1.0/c2;
244 Jp(1,6) = -u1*rho_u2*(rho_u*(k1+rho_u*(k2+k3*rho_u))+1.0)*1.0/c2;
245 Jp(1,7) = -u1*rho_u3*(rho_u*(k1+rho_u*(k2+k3*rho_u))+1.0)*1.0/c2;
250 const Eigen::Vector2d & pointDistorted,
251 Eigen::Vector2d * pointUndistorted)
const
254 Eigen::Vector2d x_bar = pointDistorted;
258 bool success =
false;
259 for (
int i = 0; i < n; i++) {
261 Eigen::Vector2d x_tmp;
265 Eigen::Vector2d e(pointDistorted - x_tmp);
266 Eigen::Matrix2d E2 = (E.transpose() * E);
267 Eigen::Vector2d du = E2.inverse() * E.transpose() * e;
271 const double chi2 = e.dot(e);
281 *pointUndistorted = x_bar;
284 std::cout << (E.transpose() * E) << std::endl;
290 const Eigen::Vector2d & pointDistorted, Eigen::Vector2d * pointUndistorted,
291 Eigen::Matrix2d * pointJacobian)
const
294 Eigen::Vector2d x_bar = pointDistorted;
298 bool success =
false;
299 for (
int i = 0; i < n; i++) {
301 Eigen::Vector2d x_tmp;
305 Eigen::Vector2d e(pointDistorted - x_tmp);
306 Eigen::Vector2d dx = (E.transpose() * E).inverse() * E.transpose() * e;
310 const double chi2 = e.dot(e);
320 *pointUndistorted = x_bar;
323 *pointJacobian = E.inverse();
bool undistort(const Eigen::Vector2d &pointDistorted, Eigen::Vector2d *pointUndistorted) const
Undistortion only.
Definition: RadialTangentialDistortion8.hpp:249
double k1_
radial parameter 1
Definition: RadialTangentialDistortion8.hpp:177
double k5_
radial parameter 3
Definition: RadialTangentialDistortion8.hpp:183
double k6_
radial parameter 4
Definition: RadialTangentialDistortion8.hpp:184
double k2_
radial parameter 2
Definition: RadialTangentialDistortion8.hpp:178
bool distortWithExternalParameters(const Eigen::Vector2d &pointUndistorted, const Eigen::VectorXd ¶meters, Eigen::Vector2d *pointDistorted, Eigen::Matrix2d *pointJacobian=NULL, Eigen::Matrix2Xd *parameterJacobian=NULL) const
Distortion and Jacobians using external distortion intrinsics parameters.
Definition: RadialTangentialDistortion8.hpp:183
EIGEN_MAKE_ALIGNED_OPERATOR_NEW RadialTangentialDistortion8()
The default constructor with all zero ki.
Definition: RadialTangentialDistortion8.hpp:48
double k3_
radial parameter 3
Definition: RadialTangentialDistortion8.hpp:181
bool setParameters(const Eigen::VectorXd ¶meters)
set the generic parameters
Definition: RadialTangentialDistortion8.hpp:85
bool distort(const Eigen::Vector2d &pointUndistorted, Eigen::Vector2d *pointDistorted) const
Distortion only.
Definition: RadialTangentialDistortion8.hpp:103
double k4_
radial parameter 4
Definition: RadialTangentialDistortion8.hpp:182
double p1_
tangential parameter 1
Definition: RadialTangentialDistortion8.hpp:179
double p2_
tangential parameter 2
Definition: RadialTangentialDistortion8.hpp:180
static const int NumDistortionIntrinsics
Definition: RadialTangentialDistortion8.hpp:100
Eigen::Matrix< double, NumDistortionIntrinsics, 1 > parameters_
all distortion parameters
Definition: RadialTangentialDistortion8.hpp:175