6 : ndi(ci), kp(q), stereo(stereo),
7 isValid(true), useCovar(false), pointPlane(false) {}
10 :
ndi(ci),
kp(q(0), q(1), 0),
14 :
ndi(0),
kp(0, 0, 0),
38 return err.head<2>().norm();
44 return err.squaredNorm();
46 return err.head<2>().squaredNorm();
63 Eigen::Matrix<double,3,1> pc = nd.
w2n * pt;
66 Eigen::Matrix<double,2,6> jacc;
69 Eigen::Matrix<double,2,3> jacp;
76 double ipz2 = 1.0/(pz*pz);
77 if (isnan(ipz2) ) { printf(
"[SetJac] infinite jac\n"); *(
int *)0x0 = 0; }
79 double ipz2fx = ipz2*nd.
Kcam(0,0);
80 double ipz2fy = ipz2*nd.
Kcam(1,1);
82 double ipz2fxq =
qScale*ipz2fx;
83 double ipz2fyq =
qScale*ipz2fy;
84 Eigen::Matrix<double,3,1> pwt;
87 pwt = (pt-nd.
trans).head<3>();
90 Eigen::Matrix<double,3,1> dp = nd.
dRdx * pwt;
91 jacc(0,3) = (pz*dp(0) - px*dp(2))*ipz2fxq;
92 jacc(1,3) = (pz*dp(1) - py*dp(2))*ipz2fyq;
95 jacc(0,4) = (pz*dp(0) - px*dp(2))*ipz2fxq;
96 jacc(1,4) = (pz*dp(1) - py*dp(2))*ipz2fyq;
99 jacc(0,5) = (pz*dp(0) - px*dp(2))*ipz2fxq;
100 jacc(1,5) = (pz*dp(1) - py*dp(2))*ipz2fyq;
104 jacc(0,0) = (pz*dp(0) - px*dp(2))*ipz2fx;
105 jacc(1,0) = (pz*dp(1) - py*dp(2))*ipz2fy;
107 jacc(0,1) = (pz*dp(0) - px*dp(2))*ipz2fx;
108 jacc(1,1) = (pz*dp(1) - py*dp(2))*ipz2fy;
110 jacc(0,2) = (pz*dp(0) - px*dp(2))*ipz2fx;
111 jacc(1,2) = (pz*dp(1) - py*dp(2))*ipz2fy;
116 jacp(0,0) = (pz*dp(0) - px*dp(2))*ipz2fx;
117 jacp(1,0) = (pz*dp(1) - py*dp(2))*ipz2fy;
119 jacp(0,1) = (pz*dp(0) - px*dp(2))*ipz2fx;
120 jacp(1,1) = (pz*dp(1) - py*dp(2))*ipz2fy;
122 jacp(0,2) = (pz*dp(0) - px*dp(2))*ipz2fx;
123 jacp(1,2) = (pz*dp(1) - py*dp(2))*ipz2fy;
126 for (
int i=0; i<2; i++)
127 for (
int j=0; j<6; j++)
128 if (isnan(jacc(i,j)) ) { printf(
"[SetJac] NaN in jacc(%d,%d)\n", i, j); *(
int *)0x0 = 0; }
132 jpp->
Hpp = jacp.transpose() * jacp;
133 jpp->
Hcc = jacc.transpose() * jacc;
134 jpp->
Hpc = jacp.transpose() * jacc;
135 jpp->
JcTE = jacc.transpose() *
err.head<2>();
136 jpp->
Bp = jacp.transpose() *
err.head<2>();
145 Eigen::Vector3d p1 = nd.
w2i * pt;
150 printf(
"[CalcErr] negative Z! Node %d \n",
ndi);
151 if (isnan(
err[0]) || isnan(
err[1]) ) printf(
"[CalcErr] NaN!\n");
153 err = Eigen::Vector3d(0.0,0.0,0.0);
157 err.head<2>() = p1.head<2>()/p1(2);
167 double b2 = huber*huber;
168 double e2 =
err.head<2>().squaredNorm();
171 double c = 2.0*huber*sqrt(e2) - b2;
172 double w = sqrt(c/e2);
186 return err.head<2>().squaredNorm();
193 Eigen::Matrix<double,3,1> pc = nd.
w2n * pt;
196 Eigen::Matrix<double,3,3> jacp;
199 Eigen::Matrix<double,3,6> jacc;
206 double ipz2 = 1.0/(pz*pz);
207 if (isnan(ipz2) ) { printf(
"[SetJac] infinite jac\n"); *(
int *)0x0 = 0; }
209 double ipz2fx = ipz2*nd.
Kcam(0,0);
210 double ipz2fy = ipz2*nd.
Kcam(1,1);
213 double ipz2fxq =
qScale*ipz2fx;
214 double ipz2fyq =
qScale*ipz2fy;
215 Eigen::Matrix<double,3,1> pwt;
218 pwt = (pt-nd.
trans).head(3);
221 Eigen::Matrix<double,3,1> dp = nd.
dRdx * pwt;
222 jacc(0,3) = (pz*dp(0) - px*dp(2))*ipz2fxq;
223 jacc(1,3) = (pz*dp(1) - py*dp(2))*ipz2fyq;
224 jacc(2,3) = (pz*dp(0) - (px-b)*dp(2))*ipz2fxq;
227 jacc(0,4) = (pz*dp(0) - px*dp(2))*ipz2fxq;
228 jacc(1,4) = (pz*dp(1) - py*dp(2))*ipz2fyq;
229 jacc(2,4) = (pz*dp(0) - (px-b)*dp(2))*ipz2fxq;
232 jacc(0,5) = (pz*dp(0) - px*dp(2))*ipz2fxq;
233 jacc(1,5) = (pz*dp(1) - py*dp(2))*ipz2fyq;
234 jacc(2,5) = (pz*dp(0) - (px-b)*dp(2))*ipz2fxq;
238 jacc(0,0) = (pz*dp(0) - px*dp(2))*ipz2fxq;
239 jacc(1,0) = (pz*dp(1) - py*dp(2))*ipz2fy;
240 jacc(2,0) = (pz*dp(0) - (px-b)*dp(2))*ipz2fxq;
242 jacc(0,1) = (pz*dp(0) - px*dp(2))*ipz2fxq;
243 jacc(1,1) = (pz*dp(1) - py*dp(2))*ipz2fy;
244 jacc(2,1) = (pz*dp(0) - (px-b)*dp(2))*ipz2fxq;
246 jacc(0,2) = (pz*dp(0) - px*dp(2))*ipz2fxq;
247 jacc(1,2) = (pz*dp(1) - py*dp(2))*ipz2fy;
248 jacc(2,2) = (pz*dp(0) - (px-b)*dp(2))*ipz2fxq;
253 jacp(0,0) = (pz*dp(0) - px*dp(2))*ipz2fxq;
254 jacp(1,0) = (pz*dp(1) - py*dp(2))*ipz2fy;
255 jacp(2,0) = (pz*dp(0) - (px-b)*dp(2))*ipz2fxq;
257 jacp(0,1) = (pz*dp(0) - px*dp(2))*ipz2fxq;
258 jacp(1,1) = (pz*dp(1) - py*dp(2))*ipz2fy;
259 jacp(2,1) = (pz*dp(0) - (px-b)*dp(2))*ipz2fxq;
261 jacp(0,2) = (pz*dp(0) - px*dp(2))*ipz2fxq;
262 jacp(1,2) = (pz*dp(1) - py*dp(2))*ipz2fy;
263 jacp(2,2) = (pz*dp(0) - (px-b)*dp(2))*ipz2fxq;
266 for (
int i=0; i<2; i++)
267 for (
int j=0; j<6; j++)
268 if (isnan(jacc(i,j)) ) { printf(
"[SetJac] NaN in jacc(%d,%d)\n", i, j); *(
int *)0x0 = 0; }
277 jpp->
Hpp = jacp.transpose() * jacp;
278 jpp->
Hcc = jacc.transpose() * jacc;
279 jpp->
Hpc = jacp.transpose() * jacc;
280 jpp->
JcTE = jacc.transpose() *
err;
281 jpp->
Bp = jacp.transpose() *
err;
290 Eigen::Vector3d p1 = nd.
w2i * pt;
291 Eigen::Vector3d p2 = nd.
w2n * pt;
292 Eigen::Vector3d pb(nd.
baseline,0,0);
305 p1 = nd.
w2i*Eigen::Vector4d(projpt.x(), projpt.y(), projpt.z(), 1.0);
306 p2 = nd.
w2n*Eigen::Vector4d(projpt.x(), projpt.y(), projpt.z(), 1.0);
309 double invp1 = 1.0/p1(2);
311 err.head<2>() = p1.head<2>()*invp1;
313 p2 = nd.
Kcam*(p2-pb);
315 err(2) = p2(0)/p2(2);
319 printf(
"[CalcErr] negative Z! Node %d\n",
ndi);
320 if (isnan(
err[0]) || isnan(
err[1]) ) printf(
"[CalcErr] NaN!\n");
328 if (abs(
err(0)) > 1e6 || abs(
err(1)) > 1e6 || abs(
err(2)) > 1e6)
330 printf(
"\n\n[CalcErr] Excessive error.\n");
341 double b2 = huber*huber;
342 double e2 = err.squaredNorm();
345 double c = 2.0*huber*sqrt(e2) - b2;
346 double w = sqrt(c/e2);
352 return err.squaredNorm();
Eigen::Matrix< double, 3, 3 > dRdx
Derivatives of the rotation matrix transpose wrt quaternion xyz, used for calculating Jacobian wrt po...
Eigen::Matrix< double, 3, 6 > Hpc
Point-to-camera Hessian (JpT*Jc)
Eigen::Matrix< double, 3, 4 > w2i
The transform from world to image coordinates.
void setJacobiansMono_(const Node &nd, const Point &pt, JacobProds *jpp)
Set monocular jacobians/hessians.
double calcErr(const Node &nd, const Point &pt, double huber=0.0)
Calculates re-projection error and stores it in err.
Eigen::Matrix< double, 3, 3 > Kcam
Projection to frame image coordinates. pre-multiply by the frame camera matrix.
Point point
An Eigen 4-vector containing the <x, y, z, w> coordinates of the point associated with the track...
Eigen::Matrix< double, 6, 6 > Hcc
Camera-to-camera Hessian (JcT*Jc)
static const double qScale
void setJacobians(const Node &nd, const Point &pt, JacobProds *jpp)
Sets the jacobians and hessians for the projection to use for SBA.
Eigen::Matrix< double, 3, 3 > dRdy
void clearCovariance()
Clear the covariance matrix and no longer use it.
bool useCovar
Use a covariance matrix?
Proj()
Default constructor. Initializes to default values, kp = <0 0 0> and ndi = <0>. Also sets the project...
Eigen::Matrix< double, 3, 3 > Hpp
Point-to-point Hessian (JpT*Jp).
void setCovariance(const Eigen::Matrix3d &covar)
Set the covariance matrix to use for cost calculation. Without the covariance matrix, cost is calculated by: cost = ||err|| With a covariance matrix, the cost is calculated by: cost = (err)T*covar*(err)
Eigen::Vector3d err
Reprojection error.
Eigen::Matrix< double, 3, 1 > Bp
The B matrix with respect to points (JpT*Err)
void setJacobiansStereo_(const Node &nd, const Point &pt, JacobProds *jpp)
Set stereo jacobians/hessians.
double baseline
baseline for stereo
NODE holds graph nodes corresponding to frames, for use in sparse bundle adjustment. Each node has a 6DOF pose, encoded as a translation vector and rotation unit quaternion (Eigen classes). These represent the pose of the node in the world frame.
Eigen::Matrix< double, 6, 1 > JcTE
Another matrix with respect to cameras (JcT*Err)
bool stereo
Whether the projection is Stereo (True) or Monocular (False).
Eigen::Matrix< double, 3, 4 > w2n
Resultant transform from world to node coordinates.
double getErrNorm()
Get the correct norm of the error, depending on whether the projection is monocular or stereo...
double calcErrMono_(const Node &nd, const Point &pt, double huber)
Calculate error function for stereo.
Track()
Default constructor for Track.
int ndi
Node index, the camera node for this projection.
Eigen::Vector3d plane_point
Point for point-plane projections.
bool isValid
valid or not (could be out of bounds)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Matrix< double, 4, 1 > trans
Translation in homogeneous coordinates, last element is 1.0.
Eigen::Vector3d kp
Keypoint, u,v,u-d vector.
double getErrSquaredNorm()
Get the correct squared norm of the error, depending on whether the projection is monocular or stereo...
JacobProds * jp
Jacobian products.
bool pointPlane
Whether this is a point-plane match (true) or a point-point match (false).
Eigen::Vector4d Point
Point holds 3D points using in world coordinates. Currently we just represent these as 4-vectors...
double calcErrStereo_(const Node &nd, const Point &pt, double huber)
Calculate error function for stereo.
Eigen::Matrix< double, 3, 3 > dRdz
Eigen::Matrix< double, 3, 3 > covarmat
Covariance matrix for cost calculation.
Eigen::Vector3d plane_normal
Normal for point-plane projections.