본문 바로가기

English

[SLAM][En] Errors and Jacobian Derivations for SLAM Part 1

1. Introduction

This post explains the definition of various errors used in SLAM and the Jacobian derivations for nonlinear optimization.

 

The errors covered in this post are:

  • Reprojection error \begin{equation}
      \begin{aligned}
      \mathbf{e} & = \mathbf{p} - \hat{\mathbf{p}} \in \mathbb{R}^{2}
      \end{aligned} 
    \end{equation}
  • Photometric error \begin{equation}
    \begin{aligned}
    \mathbf{e} & =  \mathbf{I}_{1}(\mathbf{p}_{1})-\mathbf{I}_{2}(\mathbf{p}_{2}) \in \mathbb{R}^{1}
    \end{aligned} 
    \end{equation}
  • Relative pose error (PGO)  \begin{equation}
    \begin{aligned}
    \mathbf{e}_{ij}  = \text{Log} (\mathbf{z}_{ij}^{-1}\hat{\mathbf{z}}_{ij}) \in \mathbb{R}^{6}
    \end{aligned}
    \end{equation} 
  • Line reprojection error \begin{equation}
      \begin{aligned}
         \mathbf{e}_{l} =  \begin{bmatrix} \frac{\mathbf{x}_{s}^{\intercal}l_{c}}{\sqrt{l_{1}^{2} + l_{2}^{2}}},  & \frac{\mathbf{x}_{e}^{\intercal}l_{c}}{\sqrt{l_{1}^{2} + l_{2}^{2}}}\end{bmatrix}  \in \mathbb{R}^{2}
      \end{aligned}
    \end{equation}
  • IMU measurement error  : TBA \begin{equation} 
      \begin{aligned} 
        \mathbf{e}_{\mathcal{B}} = \begin{bmatrix} 
          \delta \alpha^{b_{k}}_{b_{k+1}} \\ 
          \delta \boldsymbol{\theta}^{b_{k}}_{b_{k+1}} \\ 
          \delta \beta^{b_{k}}_{b_{k+1}} \\ 
          \delta \mathbf{b}_{a}\\ 
          \delta \mathbf{b}_{g}\\ 
        \end{bmatrix} = \begin{bmatrix} 
          \mathbf{R}^{b_{k}}_{w}(\mathbf{p}^{w}_{b_{k+1}} - \mathbf{p}^{w}_{b_{k}} - \mathbf{v}^{w}_{b_{k}}\Delta t_{k} + \frac{1}{2} \mathbf{g}^{w}\Delta t_{k}^{2}) - \hat{\alpha}^{b_{k}}_{b_{k+1}} \\ 
          2 \Big[ \Big( \hat{\gamma}^{b_{k}}_{b_{k+1}} \Big)^{-1} \otimes (\mathbf{q}^{w}_{b_{k}})^{-1} \otimes \mathbf{q}^{w}_{b_{k+1}}  \Big]_{xyz} \\ 
          \mathbf{R}^{b_{k}}_{w} ( \mathbf{v}^{w}_{b_{k+1}} - \mathbf{v}^{w}_{b_{k}} + \mathbf{g}^{w}\Delta t_{k}) - \hat{\beta}^{b_{k}}_{b_{k+1}} \\ 
          \mathbf{b}_{a_{k+1}} - \mathbf{b}_{a_{k}} \\ 
          \mathbf{b}_{g_{k+1}} - \mathbf{b}_{g_{k}} \\ 
        \end{bmatrix} 
      \end{aligned} 
    \end{equation}

      

 

Different Jacobians are derived depending on whether the camera pose is expressed as a rotation matrix $\mathbf{R} \in SO(3)$ or a transformation matrix $\mathbf{T} \in SE(3)$.  To obtain the two Jacobians, we derive the Jacobian for SO(3) in case of reprojection error and the Jacobian for SE(3) in case of photometric error. Points in 3D space also have different Jacobians depending on how $\mathbf{X}=[X,Y,Z,W]^{\intercal}$ is expressed and inverse depth $\rho$ is expressed. .  The Jacobian derivation process for both cases is also described.

 

The Jacobians covered in this post are:

  • Camera pose (SO(3)-based) \begin{equation}
      \begin{aligned}
    \frac{\partial \mathbf{e}}{\partial \mathbf{R}} \rightarrow \frac{\partial \mathbf{e}}{\partial \Delta \mathbf{w}}  \end{aligned} 
    \end{equation}
  • Camera pose (SE(3)-based) \begin{equation}
      \begin{aligned}
    \frac{\partial \mathbf{e}}{\partial \mathbf{T}} \rightarrow \frac{\partial \mathbf{e}}{\partial \Delta \xi}  \end{aligned} 
    \end{equation}
  • Map point \begin{equation}
      \begin{aligned}
    \frac{\partial \mathbf{e}}{\partial \mathbf{X}} \end{aligned} 
    \end{equation}
  • Relative pose (SE(3)-based) \begin{equation}
      \begin{aligned}
    & \frac{\partial \mathbf{e}_{ij}}{\partial \Delta \xi_{i}},  \frac{\partial \mathbf{e}_{ij}}{\partial \Delta \xi_{j}} \end{aligned} 
    \end{equation} 
  • 3D plücker line \begin{equation}
      \begin{aligned}
    & \frac{\partial \mathbf{e}_{l}}{\partial l}, \frac{\partial l}{\partial \mathcal{L}_{c}}, \frac{\partial \mathcal{L}_{c}}{\partial \mathcal{L}_{w}}, \frac{\partial \mathcal{L}_{w}}{\partial\delta_{\boldsymbol{\theta}}} \end{aligned} 
    \end{equation}  
  • Quaternion representation \begin{equation}
      \begin{aligned}
    & \frac{\partial \mathbf{X}'}{\partial \mathbf{q}} 
    \end{aligned} \end{equation}  
  • Camera intrinsics \begin{equation}
      \begin{aligned}
    & \frac{\partial \mathbf{e}}{\partial f_{x}}, \frac{\partial \mathbf{e}}{\partial f_{y}}, \frac{\partial \mathbf{e}}{\partial c_{x}}, \frac{\partial \mathbf{e}}{\partial c_{y}} \end{aligned} 
    \end{equation}  
  • Inverse depth  \begin{equation}
      \begin{aligned}
    \frac{\partial \mathbf{e}}{\partial \rho} \end{aligned} 
    \end{equation}  
  • IMU error-state system kinematics : TBA \begin{equation}   \begin{aligned}    \mathbf{J}^{b_{k}}_{b_{k+1}}, \mathbf{P}^{b_{k}}_{b_{k+1}}, \mathbf{F}, \mathbf{G}  \end{aligned} \end{equation}
  • IMU measurement : TBA \begin{equation}   \begin{aligned} 
        \frac{\partial \mathbf{e}_{\mathcal{B}} }{\partial [\mathbf{p}^{w}_{b_{k}}, \mathbf{q}^{w}_{b_{k}}]},\frac{\partial \mathbf{e}_{\mathcal{B}} }{\partial [\mathbf{v}^{w}_{b_{k}}, \mathbf{b}_{a_{k}}, \mathbf{b}_{g_{k}}]} , \frac{\partial \mathbf{e}_{\mathcal{B}} }{\partial [\mathbf{p}^{w}_{b_{k+1}}, \mathbf{q}^{w}_{b_{k+1}}]}, \frac{\partial \mathbf{e}_{\mathcal{B}} }{\partial [\mathbf{v}^{w}_{b_{k+1}}, \mathbf{b}_{a_{k+1}}, \mathbf{b}_{g_{k+1}}]}
      \end{aligned} 
    \end{equation}

 

2. Optimization formulation

2.1. Error derivation

In SLAM, error is defined as the difference between an observed value (measurement) $\mathbf{z}$ based on sensor data and an estimated value  $\hat{\mathbf{z}}$ based on mathematical modeling.

\begin{equation}
\boxed{ \begin{aligned}
\mathbf{e}(\mathbf{x}) = \mathbf{z} - \mathbf{\hat{z}}(\mathbf{x})
\end{aligned} }
\end{equation}

- $\mathbf{x}$: state variable for the model

 

As above, the difference between the observed value and the predicted value is set as the error, and the optimal state variable $\mathbf{x}$ that minimizes the error is calculated as an optimization problem in SLAM.  At this time, since the state variables of SLAM in general include non-linear terms related to rotation, the non-linear least squares method is mainly used.

 

2.2. Error function derivation

In general, when a large amount of sensor data comes in, dozens to hundreds of errors are calculated in the form of vectors.  At this time, it is assumed that the error follows a normal distribution, and the work of transforming it into an error function is performed.

\begin{equation}
\begin{aligned}
\mathbf{e}(\mathbf{x}) = \mathbf{z} - \mathbf{\hat{z}}  \sim \mathcal{N}(\mathbf{\hat{z}}, \mathbf{\Sigma})
\end{aligned}
\end{equation}

 

The multivariate normal distribution for modeling the error function is

\begin{equation}
\begin{aligned}
p(\mathbf{x})=\frac{1}{\sqrt{(2\pi)^n|\boldsymbol\Sigma|}}
\exp\left(-\frac{1}{2}({\mathbf{x}}-{\mu})^{\intercal}{\boldsymbol\Omega}({\mathbf{x}}-{\mu})
\right) \sim \mathcal{N}(\mu, \mathbf{\Sigma})
\end{aligned}
\end{equation}

- $\mathbf{\Omega} = \mathbf{\Sigma}^{-1}$ : information matrix (inverse of covariance matrix)

 

We can model the error as a multivariate normal distribution with mean $\mathbf{\hat{z}}$ and variance $\mathbf{\Sigma}$.  $\ln p(\mathbf{z})$ obtained by applying log-likelihood to the expression is as follows.

\begin{equation}
\begin{aligned}
\ln p(\mathbf{z}) & \propto -\frac{1}{2}(\mathbf{z} - \mathbf{\hat{z}})^{T}\mathbf{\Omega}(\mathbf{z} - \mathbf{\hat{z}}) \\
& \propto -\frac{1}{2}\mathbf{e}^{\intercal}\mathbf{\Omega}\mathbf{e}
\end{aligned}
\end{equation}

 

If you find the $\mathbf{x}^{*}$ where the log-likelihood $\ln p(\mathbf{z})$ is maximized, the probability of the multivariate normal distribution is maximized.  This is called Maximum Liklihood Estimation (MLE).  Since $\ln p(\mathbf{z})$ has a negative number (-) in front of it, if you find $\ln p(\mathbf{z})$ that minimizes the negative log-likelihood, you get:

\begin{equation}
\begin{aligned}
\mathbf{x}^{*} = \arg\max p(\mathbf{z})= \arg\min\mathbf{e}^{T}\mathbf{\Omega}\mathbf{e}
\end{aligned}
\end{equation}

 

When all errors are added together, instead of a single error, it is expressed as follows, and this is called the error function $\mathbf{E}$.  In an actual optimization problem, we find $\mathbf{x}^{*}$ that minimizes the error function $\mathbf{E}$ rather than a single error $\mathbf{e}_{i}$.

\begin{equation}
\boxed { \begin{aligned}
\mathbf{E}(\mathbf{x}) & = \sum_{i}\mathbf{e}_{i}^{T}\mathbf{\Omega}_{i}\mathbf{e}_{i} \\
\mathbf{x}^{*} & = \arg\min \mathbf{E}(\mathbf{x})
\end{aligned} }
\end{equation}

 

2.3. Non-linear least squares

The final optimization equation to be solved is: 

\begin{equation}
\begin{aligned}
\mathbf{x}^{*} = \arg\min \mathbf{E}(\mathbf{x}) = \arg\min \sum_{i}\mathbf{e}_{i}^{T}\mathbf{\Omega}_{i}\mathbf{e}_{i}
\end{aligned}
\end{equation}

 

In the above formula, we need to find the optimal parameter $\mathbf{x}^{*}$ that minimizes the error.  However, the above formula does not have a closed-form solution because it usually includes non-linear terms for rotation in SLAM.  Therefore, it is necessary to solve the problem using nonlinear optimization methods (Gauss-Newton (GN), Levenberg-Marquardt (LM)).  Among the actual implemented SLAM codes, information matrix $\mathbf{\Omega}_{i}$ is often set to $\mathbf{I}_{3}$ to find the optimal value for $\mathbf{e}_{i}^{\intercal}\mathbf{e}_{i}$.

 

For example, suppose we solve the problem using the GN method.  The order of solving the problem is as follows.

  1. define the error function
  2. Approximate linearization with Taylor expansion
  3. Set to 0 after the first derivative.
  4. At this time, find the value and substitute it into the error function.
  5. Repeat until the values ​​converge.

 

The detailed expression of the error function $\mathbf{e}$ is equivalent to $\mathbf{e}(\mathbf{x})$, which means that the value of the error function varies depending on the robot's pose vector $\mathbf{x}$. do.  The GN method iteratively updates the incremental amount $\Delta \mathbf{x}$ in the direction of decreasing error in $\mathbf{e}(\mathbf{x})$.
\begin{equation}
\begin{aligned}
    \mathbf{e}(\mathbf{x}+\Delta \mathbf{x})^{\intercal}\Omega\mathbf{e}(\mathbf{x}+\Delta \mathbf{x})
\end{aligned}
\end{equation}

At this time, if $\mathbf{e}(\mathbf{x}+\Delta \mathbf{x})$ is used for the first-order Taylor expansion around $\mathbf{x}$, the above expression is approximated as follows.
\begin{equation}
\begin{aligned}
\mathbf{e}(\mathbf{x} + \Delta \mathbf{x}) \rvert_{\mathbf{x}} & \approx \mathbf{e}(\mathbf{x}) + \mathbf{J}(\mathbf{x} + \Delta \mathbf{x} - \mathbf{x})\\
& = \mathbf{e}(\mathbf{x}) + \mathbf{J}\Delta \mathbf{x}
\end{aligned}
\end{equation}

In this case, $\mathbf{J} = \frac{\partial \mathbf{e}(\mathbf{x} + \Delta \mathbf{x})}{\partial \mathbf{x}}$.  Applying this to the entire error function gives:
\begin{equation}
\begin{aligned}
    \mathbf{e}(\mathbf{x}+\Delta \mathbf{x})^{\intercal}\Omega\mathbf{e}(\mathbf{x}+\Delta \mathbf{x}) \approx (\mathbf{e}+\mathbf{J}\Delta \mathbf{x})^{\intercal}\Omega
(\mathbf{e}+\mathbf{J}\Delta \mathbf{x})
\end{aligned}
\end{equation}

Expanding the above expression and substituting it gives:

\begin{equation}
\begin{aligned}
& = \underbrace{\mathbf{e}^{\intercal}\Omega\mathbf{e}}_{\mathbf{c}} + 2 \underbrace{\mathbf{e}^{\intercal}\Omega\mathbf{J}}_{\mathbf{b}} \Delta \mathbf{x} + \Delta \mathbf{x}^{\intercal} \underbrace{\mathbf{J}^{\intercal}\Omega\mathbf{J}}_{\mathbf{H}} \Delta \mathbf{x} \\
& = \mathbf{c}+ 2\mathbf{b}\Delta \mathbf{x} + \Delta \mathbf{x}^{\intercal} \mathbf{H} \Delta \mathbf{x}
\end{aligned}
\end{equation}

Applying this to the total error gives:

\begin{equation}
\begin{aligned}
    \mathbf{E}(\mathbf{x}+\Delta \mathbf{x}) = \sum_{i}\mathbf{e}_{i}^{\intercal}\Omega_{i}\mathbf{e}_{i} = \mathbf{c}+ 2\mathbf{b}\Delta \mathbf{x} + \Delta \mathbf{x}^{T} \mathbf{H} \Delta \mathbf{x}
\end{aligned}
\end{equation}

$\mathbf{E} (\mathbf{x}+\Delta \mathbf{x})$ is the quadratic form of $\Delta \mathbf{x}$ and $\mathbf{H} = \mathbf{J}^{\intercal}\Omega \mathbf{J}$ is a positive definite matrix, the first derivative of $\mathbf{E}(\mathbf{x} + \Delta \mathbf{x})$ is reduced to zero. The set value becomes the minimum of $\Delta \mathbf{x}$.

\begin{equation}
\begin{aligned}
    \frac{\partial \mathbf{E}(\mathbf{x}+\Delta \mathbf{x})}{\partial \Delta \mathbf{x}}  \approx 2\mathbf{b} + 2\mathbf{H} \Delta \mathbf{x} = 0
\end{aligned}
\end{equation}

Summarizing this, the following formula is derived:
\begin{equation}
\begin{aligned}
    \mathbf{H}\Delta \mathbf{x} = - \mathbf{b}
\end{aligned}
\end{equation}

$\Delta \mathbf{x} = -\mathbf{H}^{-1}\mathbf{b}$ obtained in this way is updated to $\mathbf{x}$.

\begin{equation}
\begin{aligned}
        \mathbf{x} \leftarrow \mathbf{x} + \Delta \mathbf{x}
\end{aligned}
\end{equation}

The algorithm that performs the process iteratively so far is called the Gauss-Newton method.  Compared to the GN method, the LM method has the same overall process, but a damping factor $\lambda $ term is added in the formula for calculating the increment.

\begin{equation}
\begin{aligned}
& \text{(GN) }\mathbf{H}\Delta \mathbf{x} = - \mathbf{b} \\
& \text{(LM) }(\mathbf{H} + \lambda \mathbf{I})\Delta \mathbf{x} = - \mathbf{b}
\end{aligned}
\end{equation}

 

3. Reprojection error

Reprojection error is an error mainly used in feature-based Visual SLAM.  It is mainly used when performing visual odometry (VO) or bundle adjustment (BA) based on feature-based methods.  For more information about BA, see [SLAM] Bundle Adjustment 개념 리뷰 post

NOMENCLATURE of reprojection error

  • $\tilde{\mathbf{p}} = \pi_{h}(\cdot)$
    • A non-homogeneous transformation of the point $\mathbf{X}'$ in 3-dimensional space for projection onto the image plane.
    • $\tilde{\mathbf{p}} : \begin{bmatrix} X' \\ Y' \\ Z' \\1 \end{bmatrix} \rightarrow   \frac{1}{Z'} \tilde{\mathbf{X}}' = \begin{bmatrix} X'/Z' \\ Y'/Z' \\ 1  \end{bmatrix}   = \begin{bmatrix} \tilde{u} \\ \tilde{v} \\ 1 \end{bmatrix}$
  • $\hat{\mathbf{p}} = \pi_{k}(\cdot)$
    • A point projected onto the image plane after correcting for lens distortion.  If distortion correction has already been performed at the input stage, $\pi_{k}(\cdot) = \tilde{\mathbf{K}}(\cdot)$.
    • $\hat{\mathbf{p}} = \tilde{\mathbf{K}} \tilde{\mathbf{p}} = \begin{bmatrix} f & 0 & c_{x} \\ 0 & f & c_{y} \end{bmatrix} \begin{bmatrix} \tilde{u} \\ \tilde{v} \\ 1 \end{bmatrix}= \begin{bmatrix} f\tilde{u} + c_{x} \\ f\tilde{v} + c_{y} \end{bmatrix} = \begin{bmatrix} u \\ v \end{bmatrix}$
  • $\mathbf{K} = \begin{bmatrix} f & 0 & c_{x} \\ 0 & f & c_{y} \\ 0 & 0 & 1 \end{bmatrix}$: Camera intrinsic matrix
  • $\tilde{\mathbf{K}} = \begin{bmatrix} f & 0 & c_{x} \\ 0 & f & c_{y}  \end{bmatrix}$: I omitted the last line of internal parameters to project to $\mathbb{P}^{2} \rightarrow \mathbb{R}^{2}$.
  • $\mathcal{X} = [\mathcal{T}_{1}, \cdots, \mathcal{T}_{m}, \mathbf{X}_{1}, \cdots, \mathbf{X}_{n}]^{\intercal}$: State variable of model
  • $m$ : number of camera poses
  • $n$: number of 3D points
  • $\mathcal{T}_{i} = [\mathbf{R}_{i}, \mathbf{t}_{i}]$
  • $\mathbf{e}_{ij} = \mathbf{e}_{ij}(\mathcal{X})$: $\mathcal{X}$ is sometimes omitted for brevity.
  • $\mathbf{p}_{ij}$: The pixel coordinates of the observed load
  • $\hat{\mathbf{p}}_{ij}$: Pixel Coordinates of Estimated Feature Points
  • $\mathbf{T}_{i}\mathbf{X}_{j}$: Transform the 3D point $\mathbf{X}_{j}$ into the camera coordinate system $\{i\}$, $\bigg( \mathbf{T}_{i}\mathbf{X}_{j} = \begin{bmatrix} \mathbf{R}_{i} \mathbf{X}_{j} + \mathbf{t}_{i} \\ 1 \end{bmatrix}  \in \mathbb{R}^{4\times1} \bigg)$
    • $\mathbf{X}' = \mathbf{TX} = [X', Y', Z',1]^{\intercal} = [\tilde{\mathbf{X}}', 1]^{\intercal} $
  • $\oplus$ : Operator that can update the rotation matrix $\mathbf{R}$, three-dimensional vectors $\mathbf{t}, and \mathbf{X}$ at once.
  • $\mathbf{J} = \frac{\partial \mathbf{e}}{\partial \mathcal{X}} = \frac{\partial \mathbf{e}}{\partial [\mathcal{T}, \mathbf{X}]}$
  • $\mathbf{w} = \begin{bmatrix} w_{x}&w_{y}&w_{z} \end{bmatrix}^{\intercal}$: Angular velocity
  • $[\mathbf{w}]_{\times} = \begin{bmatrix} 0 & -w_{z} & w_{y} \\ w_{z} & 0 & -w_{x} \\ -w_{y} & w_{x} & 0 \end{bmatrix}$ : Skew-symmetric matrix of angular velocity $\mathbf{w}$

$\mathbf{X}_{j}$ is projected onto the image plane through the following transformation.

\begin{equation} \begin{aligned} \text{projection model:     }\quad\hat{\mathbf{p}}_{ij} = \pi(\mathbf{T}_{i}, \mathbf{X}_{j}) \end{aligned} \end{equation}

A model that utilizes intrinsic/extrinsic parameters of the camera as above is called a projection model.  The reprojection error through this is defined as follows.

\begin{equation}
\boxed{
  \begin{aligned}
  \mathbf{e}_{ij} & = \mathbf{p}_{ij} - \hat{\mathbf{p}}_{ij} \\
& = \mathbf{p}_{ij} - \pi(\mathbf{T}_{i}, \mathbf{X}_{j}) \\
& = \mathbf{p}_{ij} - \pi_{k}(\pi_{h}(\mathbf{T}_{i}\mathbf{X}_{j}))
  \end{aligned} } \label{eq:reproj1}
\end{equation}

 

The error function for all camera poses and 3D points is defined as

\begin{equation}
  \begin{aligned}
 \mathbf{E}(\mathcal{X}) & =  \arg\min_{\mathcal{X}^{*}} \sum_{i}\sum_{j} \left\| \mathbf{e}_{ij} \right\|^{2} \\
& = \arg\min_{\mathcal{X}^{*}} \sum_{i}\sum_{j} \mathbf{e}_{ij}^{\intercal}\mathbf{e}_{ij} \\
& = \arg\min_{\mathcal{X}^{*}} \sum_{i}\sum_{j} (\mathbf{p}_{ij} - \hat{\mathbf{p}}_{ij})^{\intercal}(\mathbf{p}_{ij} - \hat{\mathbf{p}}_{ij})
  \end{aligned} \label{eq:10}
\end{equation}

 

$\left\|\mathbf{e}(\mathcal{X}^{*})\right\|^{2}$ that satisfies $\mathbf{E}(\mathcal{X}^{*})$ can be computed iteratively through non-linear least squares.  The optimal state is found by iteratively updating $\mathcal{X}$ in small increments $\Delta \mathcal{X}$.
\begin{equation}
  \begin{aligned}
    \mathbf{E}(\mathcal{X} + \Delta \mathcal{X}) & = \arg\min_{\mathcal{X}^{*}} \sum_{i}\sum_{j} \left\|\mathbf{e}(\mathcal{X} +\Delta \mathcal{X})\right\|^{2} 
  \end{aligned}
\end{equation}

Strictly speaking, since the state increment $\Delta \mathcal{X}$ includes the SO(3) rotation matrix, it is correct to add it to the existing state $\mathcal{X}$ through the $\oplus$ operator, but for convenience of expression The $+$ operator is used.

\begin{equation}
  \begin{aligned}
        \mathbf{e}( \mathcal{X} \oplus \Delta \mathcal{X}) 
\quad \rightarrow \quad\mathbf{e}(\mathcal{X} + \Delta \mathcal{X})
  \end{aligned}
\end{equation}

 

The above equation can be expressed as follows through Taylor's first-order approximation.

\begin{equation}
  \begin{aligned}
\mathbf{e}(\mathcal{X} + \Delta \mathcal{X})  & \approx \mathbf{e}(\mathcal{X}) + \mathbf{J}\Delta \mathcal{X} \\ & = \mathbf{e}(\mathcal{X}) + \mathbf{J}_{c} \Delta \mathcal{T} + \mathbf{J}_{p} \Delta \mathbf{X} \\
& = \mathbf{e}(\mathcal{X}) + \frac{\partial \mathbf{e}}{\partial \mathcal{T}} \Delta \mathcal{T} + \frac{\partial \mathbf{e}}{\partial \mathbf{X}}\Delta \mathbf{X} \\
  \end{aligned}
\end{equation}

 

\begin{equation}
  \begin{aligned}
    \mathbf{E}(\mathcal{X} + \Delta \mathcal{X}) & \approx \arg\min_{\mathcal{X}^{*}} \sum_{i}\sum_{j} \left\|\mathbf{e}(\mathcal{X}) + \mathbf{J}\Delta \mathcal{X} \right\|^{2} \\
  \end{aligned}
\end{equation}

 

By differentiating this, the optimal value of increment $\Delta \mathcal{X}^{*}$ is obtained as follows.  The detailed derivation process is omitted in this section.  If you want to know more about the induction process, you can refer to the previous section 
\begin{equation}
  \begin{aligned}
    & \mathbf{J}^{\intercal}\mathbf{J} \Delta \mathcal{X}^{*} = -\mathbf{J}^{\intercal}\mathbf{e} \\ 
    & \mathbf{H}\Delta \mathcal{X}^{*} = - \mathbf{b} \\
  \end{aligned} \label{eq:6}
\end{equation}

 

Since the above equation is in the form of a linear system $\mathbf{Ax} = \mathbf{b}$, various linear algebra techniques such as schur complement and cholesky decomposition can be used to find $\Delta \mathcal{X}^{*}$ .  At this time, $\mathbf{t}$ and $\mathbf{X}$ out of the existing states $\mathcal{X}$ exist in the linear vector space, so there is no difference whether adding from the right side or from the left side.  However, since the rotation matrix $\mathbf{R}$ belongs to the nonlinear SO(3) family, depending on whether it is multiplied by the right or left, the pose seen in the local coordinate system (right) or the pose seen in the global coordinate system is updated. (left) will change.  Reprojection errors update the global coordinate system's transformation matrix, so we usually use the left multiplication method.

\begin{equation}
  \begin{aligned}
    \mathcal{X} \leftarrow  \mathcal{X} \oplus \Delta \mathcal{X}^{*} \\
  \end{aligned}
\end{equation}

 

Since $\mathcal{X}$ is composed of $[\mathcal{T}, \mathbf{X}]$, it can be written as follows.

\begin{equation}
  \begin{aligned}
    \mathcal{T} \leftarrow  \mathcal{T} &  \oplus \Delta \mathcal{T}^{*}\\
    \mathbf{X} \leftarrow \mathbf{X} &  \oplus \Delta \mathbf{X}^{*}   \\
  \end{aligned} 
\end{equation}

 

The definition of the left multiplication $\oplus$ operation is as follows.

\begin{equation}
  \begin{aligned}
\mathbf{R}  \oplus \Delta \mathbf{R}^{*} & = \Delta \mathbf{R}^{*} \mathbf{R} \\ 
& = \exp([\Delta \mathbf{w}^{*}]_{\times})\mathbf{R} \quad \cdots \text{ globally updated (left mult)} \\ 
\mathbf{t} \oplus  \Delta \mathbf{t}^{*} & =  \mathbf{t} + \Delta \mathbf{t}^{*} \\
\mathbf{X} \oplus \Delta \mathbf{X}^{*}  & =  \mathbf{X}  + \Delta \mathbf{X}^{*}
  \end{aligned} \label{eq:1}
\end{equation}

 

3.1. Jacobian of the reprojection error

3.1.1. Jacobian of camera pose

The Jacobian $\mathbf{J}_{c}$ for a pose can be decomposed as:
\begin{equation} \begin{aligned} \mathbf{J}_{c} = \frac{\partial \mathbf{e}}{\partial \mathcal{T}} & = \frac{\partial}{\partial \mathcal{T}}(\mathbf{p} - \hat{\mathbf{p}}) \\ & = \frac{\partial }{\partial \mathcal{T}} \bigg(\mathbf{p} - \pi_{k}(\pi_{h}(\mathbf{T}_{i} \mathbf{X}_{j})) \bigg ) \\ & = \frac{\partial}{\partial \mathcal{T}} \bigg(-\pi_{k}(\pi_{h}(\mathbf{T}_{i} \mathbf{X}_{j})) \bigg ) \end{aligned} \end{equation}

 

By rearranging the above equation using the chain rule, we get:  At this time, for convenience, it is expressed as $\mathbf{T}_{i}\mathbf{X}_{j} \rightarrow \mathbf{X}' $.

\begin{equation}
  \begin{aligned}
    \mathbf{J}_{c}& = \frac{\partial \hat{\mathbf{p}}}{\partial \tilde{\mathbf{p}}} 
    \frac{\partial \tilde{\mathbf{p}}}{\partial \mathbf{X}'}
    \frac{\partial \mathbf{X}'}{\partial [\mathbf{w}, \mathbf{t}]} \\
     & = \mathbb{R}^{2 \times 3} \cdot \mathbb{R}^{3\times 4} \cdot \mathbb{R}^{4 \times 6} = \mathbb{R}^{2 \times 6}
  \end{aligned} \label{eq:2}
\end{equation}

 

At this time, the reason why the Jacobian $\frac{\partial \mathbf{X}'}{\partial \mathbf{w}}$ for the angular velocity $\mathbf{w}$ instead of the Jacobian $\frac{\partial \mathbf{X}'}{\partial \mathbf{R}}$ for the rotation matrix $\mathbf{R}$ will be explained in the next section. In addition, the sign of $\mathbf{J}_{c}$ is also changed depending on whether the error is defined as $\mathbf{p} - \hat{\mathbf{p}}$ or $\hat{\mathbf{p}} - \mathbf{p}$ , so this should be applied with care when implementing the actual code. In the data, the sign was considered and marked as $+$.

 

Assuming that undistortion has already been performed during the image input process, $\frac{\partial \hat{\mathbf{p}}}{\partial \tilde{\mathbf{p}}}$ is as follows.
\begin{equation}
  \boxed{
  \begin{aligned}
    \frac{\partial \hat{\mathbf{p}}}{\partial \tilde{\mathbf{p}}} & = 
    \frac{\partial }{\partial \tilde{\mathbf{p}}} \tilde{\mathbf{K}} \tilde{\mathbf{p}} \\
    & = \tilde{\mathbf{K}} \\
    & = \begin{bmatrix} f & 0 & c_{x} \\ 0 & f & c_{y} \end{bmatrix} \in \mathbb{R}^{2 \times 3}
  \end{aligned} }
\end{equation}

Next, $\frac{\partial \tilde{\mathbf{p}}}{\partial \mathbf{X}'}$ is:
\begin{equation}
  \boxed{
  \begin{aligned}
    \frac{\partial \tilde{\mathbf{p}}}{\partial \mathbf{X}'} & = 
    \frac{\partial [\tilde{u}, \tilde{v}, 1]}{\partial [X', Y', Z',1]} \\
    & = \begin{bmatrix} \frac{1}{Z'} & 0 & \frac{-X'}{Z'^{2}} & 0 \\
    0 & \frac{1}{Z'} & \frac{-Y'}{Z'^{2}} & 0 \\ 0 & 0 & 0 & 0 \end{bmatrix} \in \mathbb{R}^{3\times 4}
  \end{aligned} }
\end{equation}

 

Next, we need to find $\frac{\partial \mathbf{X}'}{\partial \mathbf{t}}$.  This can be obtained relatively simply as follows.
\begin{equation}
  \boxed{
  \begin{aligned}
    \frac{\partial \mathbf{X}'}{\partial \mathbf{t}} & = \frac{\partial }{\partial [t_{x}, t_{y}, t_{z}]} \begin{bmatrix} \mathbf{R}\mathbf{X} + \mathbf{t} \\ 1 \end{bmatrix} \\
    & = \frac{\partial }{\partial [t_{x}, t_{y}, t_{z}]} \begin{bmatrix} \mathbf{t} \\ 0 \end{bmatrix} \\
    & = \frac{\partial }{\partial [t_{x}, t_{y}, t_{z}]}(\begin{bmatrix} t_{x} \\ t_{y} \\ t_{z} \\ 0 \end{bmatrix}) \\
    & = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & 0 & 0 \end{bmatrix} \in \mathbb{R}^{4\times 3}
  \end{aligned} }
\end{equation}

 

3.1.2. Lie theory-based SO(3) optmization

Finally, we need to find $\frac{\partial \mathbf{X}'}{\partial \mathbf{w}}$.  At this time, rotation-related parameters are expressed as angular velocity $\mathbf{w}$ rather than rotation matrix $\mathbf{R}$.  The rotation matrix $\mathbf{R}$ is over-parameterized because the number of parameters is 9, but the actual rotation is limited to 3 degrees of freedom.  Disadvantages of over-parameterized representation are as follows.

  • Since redundant parameters must be calculated, the amount of computation increases during optimization.
  • The additional degrees of freedom can lead to numerical instability problems.
  • Whenever a parameter is updated, it must always be checked whether the constraint is satisfied.

 

Lie theory allows optimization to be free from constraints.  Therefore, by using lie algebra so(3) $\mathbf{w}$ instead of lie group SO(3) $\mathbf{R}$, parameters can be updated freely from constraints.

\begin{equation}
  \begin{aligned}
    \mathbf{J}_{c} = \frac{\partial \mathbf{e}}{\partial [\mathbf{R}, \mathbf{t}]} \rightarrow \frac{\partial \mathbf{e}}{\partial [\mathbf{w}, \mathbf{t}]} \\
  \end{aligned}
\end{equation}

 

However, since $\mathbf{w}$ is not immediately visible in $\mathbf{X}'$, $\mathbf{X}'$ must be expressed as lie algebra. 

At this time, since we need to find the Jacobian for the $\mathbf{w}$ term related to rotation, we translate the 3D point $\mathbf{X}_{t}$ by $\mathbf{t}$ and $\mathbf{X}'$ Let be the point where the $\mathbf{X}_{t}$ at the same position is rotated by $\mathbf{R}$.

\begin{equation} \begin{aligned} \mathbf{X}_{t} & = \mathbf{X} + \mathbf{t} \\ \mathbf{X}'  & = \mathbf{R}\mathbf{X}_{t} \\ & = \exp([\mathbf{w}]{\times})\mathbf{X}_{t}   \end{aligned} \end{equation}

 

$\exp([\mathbf{w}]_{\times}) \in SO(3)$ transforms the angular velocity $\mathbf{w}$ into a 3D rotation matrix $\mathbf{R}$ by exponential mapping refers to an operation that  For more information on exponential mapping, refer to this link.

\begin{equation} \begin{aligned} \exp([\mathbf{w}]_{\times}) = \mathbf{R}   \end{aligned} \end{equation}

 

 

At this time, there are two ways to update the small lie algebra increment $\Delta \mathbf{w}$ to the existing $\exp([\mathbf{w}]_{\times})$.  First of all, there is an update method using $[1]$ basic lie algebra.  Next, there is an update method using the $[2]$ perturbation model.

\begin{equation}
  \begin{aligned}
     \exp([\mathbf{w}]_{\times}) & \leftarrow \exp([\mathbf{w} + \Delta \mathbf{w}]_{\times}) \quad \cdots \text{[1]} \\ 
     \exp([\mathbf{w}]_{\times}) &  \leftarrow \exp([\Delta \mathbf{w}]_{\times})\exp([\mathbf{w}]_{\times}) \quad \cdots \text{[2]} 
  \end{aligned}
\end{equation}

 

The relationship between the above two methods is as follows.  For details, refer to chapter 4.3.3 of this link.

\begin{equation}
\begin{aligned}
& \exp([\Delta \mathbf{w}]_{\times}) \exp([\mathbf{w}]_{\times}) = \exp([\mathbf{w}+ \mathbf{J}_{l}^{-1}\Delta \mathbf{w}]_{\times} ) \\
& \exp([\mathbf{w}+ \Delta \mathbf{w}]_{\times} ) = \exp([\mathbf{J}_{l} \Delta \mathbf{w}]_{\times}) \exp([\mathbf{w}]_{\times})
\end{aligned}
\end{equation}

 

$[1]$ Lie algebra-based update: First of all, if you directly calculate $\frac{\partial \mathbf{R}\mathbf{X}_{t}}{\partial \mathbf{w}}$ using the $[1]$ method, you will get the following A complex diet is induced.

\begin{equation} \begin{aligned}
\frac{\partial \mathbf{R}\mathbf{X}_{t} }{\partial \mathbf{w}} & = \lim_{\Delta \mathbf{w} \rightarrow 0} \frac{\exp([\mathbf{w} + \Delta \mathbf{w}]_{\times}) \mathbf{X}_{t}  - \exp([\mathbf{w}]_{\times}) \mathbf{X}_{t} }{\Delta \mathbf{w}} \\
& \approx \lim_{\Delta \mathbf{w} \rightarrow 0} \frac{ \exp([\mathbf{J}_{l}\Delta \mathbf{w}]_{\times}) (\exp([\mathbf{w}]_{\times}) \mathbf{X}_{t}  - \exp([\mathbf{w}]_{\times}) \mathbf{X}_{t} }{\Delta \mathbf{w}} \\
& \approx \lim_{\Delta \mathbf{w} \rightarrow 0} \frac{(\mathbf{I} + [\mathbf{J}_{l} \Delta \mathbf{w}]_{\times}) (\exp([\mathbf{w}]_{\times})\mathbf{X}_{t}  - \exp([\mathbf{w}]_{\times})\mathbf{X}_{t}}{\Delta \mathbf{w}} \\
& = \lim_{\Delta \mathbf{w} \rightarrow 0} \frac{[\mathbf{J}_{l}\Delta \mathbf{w}]_{\times} \mathbf{R}\mathbf{X}_{t} }{\Delta \mathbf{w}}   \quad \quad (\because \exp([\mathbf{w}]_{\times})\mathbf{X}_{t} = \mathbf{R}\mathbf{X}_{t}) \\
& = \lim_{\Delta \mathbf{w} \rightarrow 0} \frac{-[\mathbf{R}\mathbf{X}_{t}]_{\times} \mathbf{J}_{l}\Delta \mathbf{w}}{\Delta \mathbf{w}} \\
& = -[\mathbf{R}\mathbf{X}_{t}]_{\times} \mathbf{J}_{l} \\ & = -[\mathbf{X}']_{\times} \mathbf{J}_{l}
\end{aligned} \end{equation}

 

In the above equation, the second row is a form in which the left Jacobian $\mathbf{J}_{l}$ is derived using the BCH approximation, and the third row is a form in which the first-order Taylor approximation is applied for a small rotation amount $\exp([\mathbf{J}_{l} \Delta \mathbf{w}]_{\times})$. For more information about $\mathbf{J}_{l}$, refer toChapter 4 of Introduction of Visual SLAM

 

To understand the approximation of the third row, given an arbitrary rotation vector $\mathbf{w} = [w_{x}, w_{y}, w_{z}]^{\intercal}$, the rotation matrix is ​​exponential When developed in mapping form, it can be expressed as follows.

\begin{equation}
\begin{aligned}
  \mathbf{R} = \exp([\mathbf{w}]_{\times}) = \mathbf{I} +  [\mathbf{w}]_{\times} + \frac{1}{2}[\mathbf{w}]_{\times}^{2} + \frac{1}{3!}[\mathbf{w}]_{\times}^{3} + \frac{1}{4!}[\mathbf{w}]^{4}_{\times} + \cdots
\end{aligned}
\end{equation}

For a small-sized rotation matrix $\Delta \mathbf{R}$, it can be approximated as follows by ignoring higher-order terms of order 2 or higher.\begin{equation}
\begin{aligned}
  \Delta \mathbf{R} \approx  \mathbf{I} +  [\Delta \mathbf{w}]_{\times} 
\end{aligned}
\end{equation}

 

$[2]$ Perturbation model-based update: In order to obtain a simpler Jacobian without using $\mathbf{J}_{l}$, the perturbation model of $[2]$ lie algebra so(3) is generally used.  The Jacobian $\frac{\partial \mathbf{R}\mathbf{X}_{t}}{\partial \Delta \mathbf{w}}$ is obtained using the perturbation model as follows:

\begin{equation}  \begin{aligned}
\frac{\partial \mathbf{R}\mathbf{X}_{t}}{\partial \Delta \mathbf{w}} & = \lim_{\Delta \mathbf{w} \rightarrow 0} \frac{\exp([\Delta \mathbf{w}]_{\times}) \exp([\mathbf{w}]_{\times}) \mathbf{X}_{t}  - \exp([\mathbf{w}]_{\times})  \mathbf{X}_{t} }{\Delta \mathbf{w}} \\
& \approx \lim_{\Delta \mathbf{w} \rightarrow 0} \frac{(\mathbf{I} + [\Delta \mathbf{w}]_{\times}) \exp([\mathbf{w}]_{\times}) \mathbf{X}_{t} - \exp([\mathbf{w}]_{\times}) \mathbf{X}_{t}}{\Delta \mathbf{w}}  \\
& = \lim_{\Delta \mathbf{w} \rightarrow 0} \frac{[\Delta \mathbf{w}]_{\times} \mathbf{R}\mathbf{X}_{t}}{\Delta \mathbf{w}} \quad \quad (\because \exp([\mathbf{w}]_{\times})\mathbf{X}_{t}  = \mathbf{R}\mathbf{X}_{t}) \\
& = \lim_{\Delta \mathbf{w} \rightarrow 0} \frac{-[\mathbf{R}\mathbf{X}_{t}]_{\times} \Delta \mathbf{w}}{\Delta \mathbf{w}} \\
& = -[\mathbf{R}\mathbf{X}_{t}]_{\times} \\ & = -[\mathbf{X}']_{\times} \\
\end{aligned}  \end{equation}

 

The above equation also uses approximate $\exp([\Delta \mathbf{w}]_{\times}) \approx  \mathbf{I} +  [\Delta \mathbf{w}]_{\times}$ for a small rotation matrix in the second row. Therefore, when using the $[2]$ perturbation model, there is an advantage in that the Jacobian can be obtained simply by using an skew-symmetric matrix of the points $\mathbf{X}'$ in the 3D space.  In the case of reprojection error optimization, since most of the errors for the feature points of sequentially incoming images are optimized, the camera pose change is not large and the size of $\Delta \mathbf{w}$ is not large, so the Jacobian above is generally used. Since the $[2]$ method is used, when updating the small increment $\Delta \mathbf{w}$ to the existing rotation matrix $\mathbf{R}$, it is updated as (\ref{eq:1}).

\begin{equation}
\begin{aligned}
   \mathbf{R} \leftarrow \Delta \mathbf{R}^{*} \mathbf{R} \quad \text{where, } \Delta \mathbf{R}^{*} = \exp([\Delta \mathbf{w}^{*}]_{\times})
\end{aligned}
\end{equation}

 

So the original Jacobian is $\frac{\partial \mathbf{X}'}{\partial [\mathbf{w}, \mathbf{t}]}$ to $\frac{\partial \mathbf{X}' }{\partial [\Delta \mathbf{w}, \mathbf{t}]}$, which looks like this:

\begin{equation}
  \boxed{
  \begin{aligned}
    \frac{\partial }{\partial [\Delta \mathbf{w}, \mathbf{t}]} \begin{bmatrix} \mathbf{RX} + \mathbf{t} \\ 1 \end{bmatrix} & = \begin{bmatrix} 0 & Z' & - Y' & 1 & 0 & 0
      \\ -Z' & 0 & X' & 0 & 1 & 0 \\ Y' & -X' & 0 & 0 & 0 & 1 \\ 0&0&0&0&0&0 \end{bmatrix} \in \mathbb{R}^{4 \times 6}
  \end{aligned} } 
\end{equation}

The Jacobian $\mathbf{J}_{c}$ for the final pose is
\begin{equation}
  \boxed{
  \begin{aligned}
    \mathbf{J}_{c} & = \frac{\partial \hat{\mathbf{p}}}{\partial \tilde{\mathbf{p}}} 
    \frac{\partial \tilde{\mathbf{p}}}{\partial \mathbf{X}'}
    \frac{\partial \mathbf{X}'}{\partial [\Delta \mathbf{w}, \mathbf{t}]} \\
    & = \begin{bmatrix} f & 0 & c_{x} \\ 0 & f & c_{y} \end{bmatrix} \begin{bmatrix} \frac{1}{Z'} & 0 & \frac{-X'}{Z'^{2}} & 0 \\
      0 & \frac{1}{Z'} & \frac{-Y'}{Z'^{2}} & 0  \\ 0 & 0 & 0 &0  \end{bmatrix}
    \begin{bmatrix} 0 & Z' & -Y' & 1 & 0 & 0 \\
       -Z' & 0 & X' & 0 & 1 & 0 \\
      Y' & -X' & 0 & 0 & 0 & 1 \\ 0&0&0&0&0&0 \end{bmatrix} \\
 & = \begin{bmatrix} \frac{f}{Z'} & 0 & -\frac{fX}{Z'^{2}} & 0 \\ 0 & \frac{f}{Z'} & -\frac{fY}{Z'^{2}} & 0\end{bmatrix}
    \begin{bmatrix} 0 & Z' & -Y' & 1 & 0 & 0 \\ -Z' & 0 & X' & 0 & 1 & 0 \\ Y'& -X'& 0 & 0 & 0 & 1 \\ 0&0&0&0&0&0 \end{bmatrix} \\
    & = \begin{bmatrix} -\frac{fX'Y'}{Z'^{2}} & \frac{f(1 + X'^{2})}{Z'^{2}} & -\frac{fY'}{Z'} & \frac{f}{Z'} & 0 & -\frac{fX'}{Z'^{2}} \\
      -\frac{f(1+y^{2})}{Z'^{2}} & \frac{fX'Y'}{Z'^{2}} & \frac{fX'}{Z'} & 0 & \frac{f}{Z'} & -\frac{fY'}{Z'^{2}} \end{bmatrix} \in \mathbb{R}^{2 \times 6}
  \end{aligned} } 
\end{equation}

 

3.1.3. Code implementations

 

3.2. Jacobian of Map Point

The Jacobian $\mathbf{J}_{p}$ for a 3D point $\mathbf{X}$ can be obtained as follows.

\begin{equation}
  \begin{aligned}
    \mathbf{J}_{p} = \frac{\partial \mathbf{e}}{\partial \mathbf{X}} & = \frac{\partial}{\partial \mathbf{X}}(\mathbf{p} - \hat{\mathbf{p}}) \\
    & = \frac{\partial}{\partial \mathbf{X}} \bigg(\mathbf{p} - \pi_{k}(\pi_{h}(\mathbf{T}_{i} \mathbf{X}_{j})) \bigg ) \\
    & = \frac{\partial}{\partial \mathbf{X}} \bigg(-\pi_{k}(\pi_{h}(\mathbf{T}_{i} \mathbf{X}_{j})) \bigg ) \\
  \end{aligned}
\end{equation}

By rearranging the above equation using the chain rule, we get:
\begin{equation}
  \begin{aligned}
    \mathbf{J}_{p}& = \frac{\partial \hat{\mathbf{p}}}{\partial  \tilde{\mathbf{p}}} 
    \frac{\partial \tilde{\mathbf{p}}}{\partial \mathbf{X}'}
    \frac{\partial \mathbf{X}'}{\partial \mathbf{X}} \\
     & = \mathbb{R}^{2 \times 3} \cdot \mathbb{R}^{3\times 4} \cdot \mathbb{R}^{4 \times 4} = \mathbb{R}^{2 \times 4}
  \end{aligned} 
\end{equation}

Of these, $\frac{\partial \hat{\mathbf{p}}}{\partial \tilde{\mathbf{p}}} \frac{\partial \hat{\mathbf{p}}}{\partial \mathbf{X}'}$ is the same as the Jacobian obtained earlier.  So we only need to calculate $\frac{\partial \mathbf{X}'}{\partial \mathbf{X}}$.

\begin{equation}
  \boxed{
  \begin{aligned}
    \frac{\partial \mathbf{X}'}{\partial \mathbf{X}} & = \frac{\partial }{\partial \mathbf{X}} \begin{bmatrix} \mathbf{R}\mathbf{X} + \mathbf{t} \\ 1 \end{bmatrix}  \\
    & = \begin{bmatrix} \mathbf{R} \\ 0 \end{bmatrix}
  \end{aligned} }
\end{equation}

Therefore, $\mathbf{J}_{p}$ is
\begin{equation}
  \boxed{
  \begin{aligned}
    \mathbf{J}_{p} & = \begin{bmatrix} f & 0 & c_{x} \\ 0 & f & c_{y} \end{bmatrix} \begin{bmatrix} \frac{1}{Z'} & 0 & \frac{-X'}{Z'^{2}} & 0 \\
      0 & \frac{1}{Z'} & \frac{-Y'}{Z'^{2}} & 0\\ 0 & 0 & 0 & 0\end{bmatrix} \begin{bmatrix} \mathbf{R} \\ 0 \end{bmatrix} \\
    & = \begin{bmatrix} \frac{f}{Z'} & 0 & -\frac{fX'}{Z'^{2}} & 0 \\ 0 & \frac{f}{Z'} & -\frac{fY'}{Z'^{2}} & 0 \end{bmatrix} \begin{bmatrix} \mathbf{R} \\ 0 \end{bmatrix} \in \mathbb{R}^{2\times 4}
  \end{aligned} }
\end{equation}

In general, since the last column of $\mathbf{J}_{p}$ is always 0, it is sometimes omitted to represent non-homogeneous form.

\begin{equation}
  \boxed{
  \begin{aligned}
    \mathbf{J}_{p} & = \begin{bmatrix} \frac{f}{Z'} & 0 & -\frac{fX'}{Z'^{2}} \\ 0 & \frac{f}{Z'} & -\frac{fY'}{Z'^{2}} \end{bmatrix} \mathbf{R} \in \mathbb{R}^{2\times 3}
  \end{aligned} }
\end{equation}

 

3.2.1. Code implementations

 

4. Photometric error

Photometric error is an error mainly used in direct Visual SLAM.  It is mainly used when performing direct method-based visual odometry (VO) or bundle adjustment (BA).  For more information about direct methods, see [SLAM] Optical Flow와 Direct Method 개념 및 코드 리뷰 post.

 

NOMENCLATURE of photometric error

  • $\tilde{\mathbf{p}}_{2} = \pi_{h}(\cdot)$
    • A non-homogeneous transformation of the point $\mathbf{X}'$ in 3-dimensional space for projection onto the image plane.
    • $\tilde{\mathbf{p}}_{2} : \begin{bmatrix} X' \\ Y' \\ Z' \\1 \end{bmatrix} \rightarrow   \frac{1}{Z'} \tilde{\mathbf{X}}' = \begin{bmatrix} X'/Z' \\ Y'/Z' \\ 1  \end{bmatrix}   = \begin{bmatrix} \tilde{u}_{2} \\ \tilde{v}_{2} \\ 1 \end{bmatrix}$
  • $\mathbf{p}_{2} = \pi_{k}(\cdot)$
    • Projection onto the image plane after correcting for lens distortion. If distortion correction has already been performed at the input stage, then $\pi_{k}(\cdot) = \tilde{\mathbf{K}}(\cdot)$.
    • $\mathbf{p}_{2} = \tilde{\mathbf{K}} \tilde{\mathbf{p}}_{2} = \begin{bmatrix} f & 0 & c_{x} \\ 0 & f & c_{y} \end{bmatrix} \begin{bmatrix} \tilde{u}_{2} \\ \tilde{v}_{2} \\ 1 \end{bmatrix}= \begin{bmatrix} f\tilde{u} + c_{x} \\ f\tilde{v} + c_{y} \end{bmatrix} = \begin{bmatrix} u_{2} \\ v_{2} \end{bmatrix}$
  • $\mathbf{K} = \begin{bmatrix} f & 0 & c_{x} \\ 0 & f & c_{y} \\ 0 & 0 & 1 \end{bmatrix}$: Camera intrinsic matrix
  • $\tilde{\mathbf{K}} = \begin{bmatrix} f & 0 & c_{x} \\ 0 & f & c_{y}  \end{bmatrix}$: I omitted the last line of internal parameters to project to $\mathbb{P}^{2} \rightarrow \mathbb{R}^{2}$
  • $\mathcal{P}$:  The set of all feature points in the image
  • $\mathbf{e}(\mathbf{T}) \rightarrow \mathbf{e}$: In general, it is sometimes indicated simply by omitting the notation.
  • $\mathbf{p}^{i}_{1}, \mathbf{p}^{i}_{2}$: Pixel coordinates of the ith feature point in the first image and the second image
  • $\oplus$ : operator for composition of two SE(3) group
  • $\mathbf{J} = \frac{\partial \mathbf{e}}{\partial \mathbf{T}} = \frac{\partial \mathbf{e}}{\partial [\mathbf{R}, \mathbf{t}]}$
  • $\mathbf{X}' = [X,Y,Z,1]^{\intercal} = [\tilde{\mathbf{X'}}, 1]^{\intercal} = \mathbf{TX}$
  • $\mathbf{T}\mathbf{X}$: Transform 3D point $\mathbf{X}$ to camera coordinate system, $\bigg( \mathbf{T}\mathbf{X} = \begin{bmatrix} \mathbf{R} \mathbf{X} + \mathbf{t} \\ 1 \end{bmatrix}  \in \mathbb{R}^{4\times1} \bigg)$
  • $\mathbf{X}' = [X',Y',Z',1]^{\intercal} = [\tilde{\mathbf{X}}', 1]^{\intercal}$
  • $\xi = [\mathbf{w}, \mathbf{v}]^{\intercal} = [w_{x}, w_{y}, w_{z}, v_{x}, v_{y}, v_{z}]^{\intercal}$: A vector of three-dimensional angular velocity and velocity. It's called a twist.
  • $[\xi]_{\times} = \begin{bmatrix} [\mathbf{w}]_{\times} & \mathbf{v} \\ \mathbf{0}^{\intercal} & 0 \end{bmatrix} \in \text{se}(3)$ : Twist's lie algebra with hat operator applied (4x4 matrix)
  • $\mathcal{J}_{l}$: Jacobian for left multiplication. Since it is not used in actual calculations, it will not be introduced in detail.

 

In the figure above, the world coordinates of the 3D point $\mathbf{X}$ are $[X,Y,Z,1]^{\intercal} \in \mathbb{P}^{3}$ and the corresponding two cameras The pixel coordinates on the image plane are $\mathbf{p}_{1}, \mathbf{p}_{2} \in \mathbb{P}^{2}$.  At this time, it is assumed that the internal parameters $\mathbf{K}$ of the two cameras $\{C_{1}\}$ and $\{C_{2}\}$ are the same. When camera $\{C_{1}\}$ is the origin($\mathbf{R} = \mathbf{I}, \mathbf{t} = \mathbf{0}$) , if pixel coordinates $\mathbf{p}_{1}, \mathbf{p}_{2}$ are expressed through the 3D point $\mathbf{X}$, they are projected in the following order.

\begin{equation}
\begin{aligned} \mathbf{p} = \pi(\mathbf{T}, \mathbf{X})
 \end{aligned}
\end{equation} 

\begin{equation}
\begin{aligned}
\mathbf{p}_{1}  = \begin{pmatrix}
u_{1}\\v_{1}\end{pmatrix}
& = \pi(\mathbf{I}, \mathbf{X}) = \pi_{k}(\pi_{h}(\mathbf{X}))   \\
\mathbf{p}_{2}  = \begin{pmatrix} u_{2}\\ v_{2}\end{pmatrix} & = \pi(\mathbf{T}, \mathbf{X}) = \pi_{k}(\pi_{h}(\mathbf{TX}))    \\ \end{aligned}
\end{equation} 

 

One of the characteristics of direct method is that unlike feature-based, there is no way to know which $\mathbf{p}_{2}$ matches $\mathbf{p}_{1}$.  So based on the current pose estimate, we find the position of $\mathbf{p}_{2}$. That is, $\mathbf{p}_{2}$ and $\mathbf{p}_{1}$ are made similar by optimizing the pose of the camera. At this time, the problem is solved by minimizing the photometric error.  The photometric error is:

\begin{equation}
\boxed{
\begin{aligned}
\mathbf{e}(\mathbf{T}) & =  \mathbf{I}_{1}(\mathbf{p}_{1})-\mathbf{I}_{2}(\mathbf{p}_{2}) \\
& = \mathbf{I}_{1} \bigg( \pi_{k}(\pi_{h}(\mathbf{X})) \bigg)-\mathbf{I}_{2}\bigg(  \pi_{k}(\pi_{h}(\mathbf{TX})) \bigg) \\
\end{aligned} } \label{eq:photo3}
\end{equation}

 

The photometric error is based on the assumption of grayscale invariance and is scalar.  To solve non-linear least squares with photometric error, we can define the following error function $\mathbf{E}(\mathbf{T})$.

\begin{equation}
  \begin{aligned}
 \mathbf{E}(\mathbf{T}) & =  \arg\min_{\mathbf{T}^{*}} \sum_{i \in \mathcal{P}} \left\| \mathbf{e}_{i} \right\|^{2} \\
& = \arg\min_{\mathbf{T}^{*}} \sum_{i \in \mathcal{P}} \mathbf{e}_{i}^{\intercal}\mathbf{e}_{i} \\
& = \arg\min_{\mathbf{T}^{*}} \sum_{i \in \mathcal{P}} \Big( \mathbf{I}_{1}(\mathbf{p}^{i}_{1})-\mathbf{I}_{2}(\mathbf{p}^{i}_{2}) \Big)^{\intercal} \Big( \mathbf{I}_{1}(\mathbf{p}^{i}_{1})-\mathbf{I}_{2}(\mathbf{p}^{i}_{2}) \Big)
  \end{aligned}
\end{equation}

 

$\left\|\mathbf{e}(\mathbf{T}^{*})\right\|^{2}$ that satisfies $\mathbf{E}(\mathbf{T}^{*})$ can be computed iteratively through non-linear least squares.  The optimal state is found by iteratively updating $\mathbf{T}$ in small increments $\Delta \mathbf{T}$. 
\begin{equation}
  \begin{aligned}
    \mathbf{E}(\mathbf{T} + \Delta \mathbf{T}) & = \arg\min_{\mathbf{T}^{*}} \sum_{i \in \mathcal{P}} \left\|\mathbf{e}_{i}(\mathbf{T} + \Delta \mathbf{T})\right\|^{2} 
  \end{aligned}
\end{equation}

 

Strictly speaking, since the state increment $\Delta \mathbf{T}$ is an SE(3) conversion matrix, it is correct to add it to the existing state $\mathbf{T}$ through the $\oplus$ operator, but for convenience of expression, The $+$ operator is used.

\begin{equation}
  \begin{aligned}
\mathbf{T}  \oplus \Delta \mathbf{T}  \quad  \rightarrow \quad \mathbf{T} + \Delta \mathbf{T}
  \end{aligned}
\end{equation}


This can be expressed as follows through the first-order Taylor approximation.
\begin{equation}
  \begin{aligned}
    \mathbf{e}(\mathbf{T} + \Delta \mathbf{T}) & \approx \mathbf{e}_{i}(\mathbf{T}) + \mathbf{J}\Delta \mathbf{T}  \\
& = \mathbf{e}_{i}(\mathbf{T}) + \frac{\partial \mathbf{e}}{\partial \mathbf{T}}\Delta \mathbf{T}
  \end{aligned}
\end{equation}

 

\begin{equation}
  \begin{aligned}
    \mathbf{E}(\mathbf{T} + \Delta \mathbf{T}) & = \arg\min_{\mathbf{T}^{*}} \sum_{i \in \mathcal{P}} \left\|\mathbf{e}_{i}(\mathbf{T}) + \mathbf{J}\Delta \mathbf{T}\right\|^{2} 
  \end{aligned}
\end{equation}

 

By differentiating this, the optimal value of increment $\Delta \mathbf{T}^{*}$ is obtained as follows.  The detailed derivation process is omitted in this section.  If you want to know more about the induction process, you can refer to the previous section.
\begin{equation}
  \begin{aligned}
    & \mathbf{J}^{\intercal}\mathbf{J} \Delta \mathbf{T}^{*} = -\mathbf{J}^{\intercal}\mathbf{e} \\ 
    & \mathbf{H}\Delta \mathbf{T}^{*} = - \mathbf{b} \\
  \end{aligned} \label{eq:photo1}
\end{equation}

Since the above equation is in the form of a linear system $\mathbf{Ax} = \mathbf{b}$, various linear algebra techniques such as schur complement and cholesky decomposition can be used to find $\Delta \mathbf{T}^{*}$ .  The optimal increment obtained in this way is added to the current state. At this time, whether to update the pose seen in the local coordinate system (right) or the pose seen in the global coordinate system (left) depends on whether the existing $\mathbf{T}$ is multiplied to the right or to the left. will lose  Photometric errors update the transformation matrix in the global coordinate system, so the left multiplication method is generally used.
\begin{equation}
  \begin{aligned}
    \mathbf{T} \leftarrow  \mathbf{T} \oplus \Delta \mathbf{T}^{*}
  \end{aligned} 
\end{equation}

 

The definition of the left multiplication $\oplus$ operation is as follows.

\begin{equation}
  \begin{aligned}
 \mathbf{T} \oplus \Delta \mathbf{T}^{*}& = \Delta \mathbf{T}^{*}\mathbf{T} \\ & = \exp([\Delta \xi^{*}]_{\times}) \mathbf{T}  \quad \cdots \text{ globally updated (left mult)} \end{aligned} \label{eq:photo2}
\end{equation}

 

4.1. Jacobian of the photometric error

To perform (\ref{eq:photo1}), we need to find the Jacobian $\mathbf{J}$ for the photometric error.  This can be expressed as:

\begin{equation}
  \begin{aligned}
    \mathbf{J} & = \frac{\partial \mathbf{e}}{\partial \mathbf{T}}   \\
& =  \frac{\partial \mathbf{e}}{\partial [\mathbf{R}, \mathbf{t}]} 
  \end{aligned}
\end{equation}

 

Here's a closer look at this:

\begin{equation}
  \begin{aligned}
\mathbf{J} = \frac{\partial \mathbf{e}}{\partial \mathbf{T}} & = \frac{\partial }{\partial \mathbf{T}} \bigg( \mathbf{I}_{1}(\mathbf{p}_{1}) - \mathbf{I}_{2}(\mathbf{p}_{2}) \bigg) \\ & = \frac{\partial }{\partial \mathbf{T}} \bigg(
\mathbf{I}_{1} \bigg(    \pi_{k}(\pi_{h}(\mathbf{X}))   \bigg)-\mathbf{I}_{2}\bigg( \pi_{k}(\pi_{h}(\mathbf{TX})) \bigg) \bigg) \\
& =  \frac{\partial }{\partial \mathbf{T}} \bigg( -\mathbf{I}_{2}\bigg( \pi_{k}(\pi_{h}(\mathbf{TX})) \bigg) \bigg) \\ & =  \frac{\partial }{\partial \mathbf{T}} \bigg( -\mathbf{I}_{2}\bigg( \pi_{k}(\pi_{h}(\mathbf{X}')) \bigg) \bigg)
  \end{aligned}
\end{equation}

 

Re-expressing the above expression by applying the chain rule gives:

\begin{equation}
  \begin{aligned}
\frac{\partial \mathbf{e}}{\partial \xi} & =  \frac{\partial \mathbf{I}}{\partial \mathbf{p}_{2}} \frac{\partial \mathbf{p}_{2}}{\partial \tilde{\mathbf{p}}_{2}} \frac{\partial \tilde{\mathbf{p}}_{2}}{\partial \mathbf{X}'} \frac{\partial \mathbf{X}'}{\partial \xi}  \\
& = \mathbb{R}^{1\times2} \cdot \mathbb{R}^{2\times3} \cdot \mathbb{R}^{3\times4} \cdot \mathbb{R}^{4\times6} = \mathbb{R}^{1\times6} 
  \end{aligned}
\end{equation}

 

 

At this time, the Jacobian $\frac{\partial \mathbf{X}'}{\partial \mathbf{T}}$ for the transformation matrix $\mathbf{T}$ is not obtained, but for the twist $\xi$ The reason for finding the Jacobian $\frac{\partial \mathbf{X}'}{\partial \xi}$ is explained in the next section.  First of all, $\frac{\partial \mathbf{I}}{\partial \mathbf{p}_{2}}$ means the gradient of the image.

\begin{equation}
\boxed{
  \begin{aligned}
\frac{\partial \mathbf{I}}{\partial \mathbf{p}_{2}}  & =  \begin{bmatrix} \frac{\partial \mathbf{I}}{\partial u} & \frac{\partial \mathbf{I}}{\partial v} \end{bmatrix} \\
& = \begin{bmatrix} \nabla \mathbf{I}_{u} & \nabla \mathbf{I}_{v} \end{bmatrix}
  \end{aligned} } \label{eq:photo4}
\end{equation}

 

Assuming that undistortion has already been performed during the image input process, $\frac{\partial \mathbf{p}_{2}}{\partial \tilde{\mathbf{p}}_{2}}$ is as follows.
\begin{equation}
  \boxed{
  \begin{aligned}
    \frac{\partial \mathbf{p}_{2}}{\partial \tilde{\mathbf{p}}_{2}} & = 
    \frac{\partial }{\partial \tilde{\mathbf{p}}_{2}} \tilde{\mathbf{K}} \tilde{\mathbf{p}}_{2} \\
    & = \tilde{\mathbf{K}} \\
    & = \begin{bmatrix} f & 0 & c_{x} \\ 0 & f & c_{y} \end{bmatrix} \in \mathbb{R}^{2 \times 3}
  \end{aligned} }
\end{equation}


Next, $\frac{\partial \tilde{\mathbf{p}}_{2}}{\partial \mathbf{X}'}$ is:
\begin{equation}
  \boxed{
  \begin{aligned}
    \frac{\partial \tilde{\mathbf{p}}_{2}}{\partial \mathbf{X}'} & = 
    \frac{\partial [\tilde{u}_{2}, \tilde{v}_{2}, 1]}{\partial [X', Y', Z',1]} \\
    & = \begin{bmatrix} \frac{1}{Z'} & 0 & \frac{-X'}{Z'^{2}} & 0\\
    0 & \frac{1}{Z'} & \frac{-Y'}{Z'^{2}} &0 \\ 0 & 0 & 0 & 0 \end{bmatrix} \in \mathbb{R}^{3\times 4}
  \end{aligned} } \label{eq:photo5}
\end{equation}

 

4.1.1. Lie theory-based SE(3) optimization

Finally $\frac{\partial \mathbf{X}'}{\partial \mathbf{T}} = \frac{\partial \mathbf{X}'}{\partial [\mathbf{R}, \mathbf{ t}]}$.  At this time, since the term $\mathbf{t}$ related to the position is a 3D vector and the size of the vector is equal to 3 degrees of freedom, which is the minimum degree of freedom for expressing the 3D position, a separate constraint is required when performing the optimization update. does not exist. On the other hand, the rotation matrix $\mathbf{R}$ has 9 parameters, which is more than 3 degrees of freedom, which is the minimum degree of freedom for expressing 3D rotation, so various constraints exist.  This is said to be over-parameterized.  Disadvantages of over-parameterized representation are as follows.

  • Since redundant parameters must be calculated, the amount of computation increases during optimization.
  • The additional degrees of freedom can lead to numerical instability problems.
  • Whenever a parameter is updated, it must always be checked whether the constraint is satisfied.

 

Therefore, a lie theory-based optimization method, which is a minimal parameter expression free from constraints, is generally used.  Instead of calculating $\Delta \mathbf{T}^{*}$, which includes a nonlinear rotation matrix, the lie group SE(3)-based optimization method includes $\mathbf{R} \rightarrow \mathbf{w} $, and position-related terms are changed to $\mathbf{t} \rightarrow \mathbf{v}$ to find the optimal lie algebra se(3) $\Delta \xi^{*}$, and then exponential mapping Indicates how to update to SE(3).

\begin{equation}
  \begin{aligned}
    \Delta \mathbf{T}^{*} & \rightarrow \Delta \xi^{*} 
  \end{aligned}
\end{equation}

 

The Jacobian for $\xi$ is

\begin{equation}
  \begin{aligned}
    \mathbf{J}  & =  \frac{\partial \mathbf{e}}{\partial [\mathbf{R}, \mathbf{t}]} && \rightarrow  \frac{\partial \mathbf{e}}{\partial [\mathbf{w}, \mathbf{v}]}  \\
& && \rightarrow  \frac{\partial \mathbf{e}}{\partial \xi} 
  \end{aligned}
\end{equation}

 

Through this, the existing expression is changed as follows.

\begin{equation}
  \begin{aligned}
    \mathbf{e}(\mathbf{T}) \quad \quad & \rightarrow \quad \quad \mathbf{e}(\xi) \\
    \mathbf{E}(\mathbf{T}) \quad \quad & \rightarrow \quad \quad \mathbf{E}(\xi) \\
    \mathbf{e}(\mathbf{T}) + \mathbf{J}'\Delta \mathbf{T} \quad \quad & \rightarrow \quad \quad \mathbf{e}(\xi) + \mathbf{J}\Delta \xi \\
    \mathbf{H}\Delta\mathbf{T}^{*} = -\mathbf{b} \quad \quad & \rightarrow \quad \quad \mathbf{H}\Delta \xi^{*}  = -\mathbf{b} \\
\mathbf{T} \leftarrow \Delta \mathbf{T}^{*}\mathbf{T} \quad \quad & \rightarrow \quad \quad \mathbf{T} \leftarrow \exp([\Delta \xi^{*}]_{\times}) \mathbf{T} 
  \end{aligned}
\end{equation}

- $\mathbf{J}'  = \frac{\partial \mathbf{e}}{\partial \mathbf{T}} $

- $\mathbf{J}  = \frac{\partial \mathbf{e}}{\partial \xi} $

 

$\exp([\xi]_{\times}) \in \text{SE}(3)$ refers to an operation that transforms twist $\xi$ into a 3D pose by exponential mapping.  For more information on exponential mapping, refer to this link.

\begin{equation}
  \begin{aligned}
    \exp([\Delta \xi]_{\times}) = \Delta \mathbf{T} 
  \end{aligned}
\end{equation}

 

So far the Jacobians have been easy to compute, whereas $\frac{\partial \mathbf{X}'}{\partial \xi}$ is because the parameter $\xi$ is not immediately visible in $\mathbf{X}'$ $\mathbf{X}'$ should be changed to terms related to lie algebra.

\begin{equation}
  \begin{aligned}
\mathbf{X}' \rightarrow \mathbf{TX} \rightarrow \exp([\xi]_{\times})\mathbf{X}
  \end{aligned}
\end{equation}

 

At this time, there are two ways to update the small lie algebra increment $\Delta \xi$ to the existing $\exp([\xi]_{\times})$.  First of all, [1] There is an update method using basic lie algebra.  [2] Next, there is an update method using a perturbation model. 

\begin{equation}
  \begin{aligned}
     \exp([\xi]_{\times}) & \leftarrow \exp([\xi + \Delta \xi]_{\times}) \quad \cdots \text{[1]} \\ 
     \exp([\xi]_{\times}) &  \leftarrow \exp([\Delta \xi]_{\times})\exp([\xi]_{\times}) \quad \cdots \text{[2]} 
  \end{aligned}
\end{equation}

 

Among the two methods above, the $[1]$ method adds the fine increment $\Delta \xi$ to the existing $\xi$ and then performs exponential mapping to obtain the Jacobian. The $[2]$ method calculates the Jacobian. This method updates the existing state by multiplying the left side of $\xi$ by the perturbation model $\exp([\Delta \xi]_{\times})$.  The following conversion exists between the two methods, which is called the BCH approximation.  For details, see Chapter 4 of Introduction to Visual SLAM.

\begin{equation}
  \begin{aligned}
    \exp([\Delta \xi]_{\times})\exp([\xi]_{\times}) & = \exp([\xi + \mathcal{J}^{-1}_{l}\Delta \xi]_{\times}) \\
    \exp([\xi + \Delta \xi]_{\times}) & = \exp([\mathcal{J}_{l}\Delta \xi]_{\times})\exp([\xi]_{\times}) \\
  \end{aligned} \label{eq:bch}
\end{equation}

 

Since using the $[1]$ method leads to very complex equations, this method is not often used, and the perturbation model of $[2]$ is mainly used.  Therefore, $\frac{\partial \mathbf{X}'}{\partial \xi}$ is transformed as follows.

\begin{equation}
  \begin{aligned}
    \frac{\partial \mathbf{X}'}{\partial \xi} & \rightarrow \frac{\partial \mathbf{X}'}{\partial \Delta \xi}
  \end{aligned}
\end{equation}

 

The Jacobian for $\frac{\partial \mathbf{X}'}{\partial \Delta \xi}$ can be calculated as

\begin{equation} \boxed{ \begin{aligned}
\frac{\partial \mathbf{X}'}{\partial \Delta \xi} & = \lim_{\Delta \xi \rightarrow 0} \frac{\exp([\Delta \xi]_{\times}) \mathbf{X}' - \mathbf{X}'}{\Delta \xi} \\
& \approx \lim_{\Delta \xi \rightarrow 0} \frac{(\mathbf{I} + [\Delta \xi]_{\times})\mathbf{X}' - \mathbf{X}'}{\Delta \xi} \\
& = \lim_{\Delta \xi \rightarrow 0} \frac{[\Delta \xi]_{\times}\mathbf{X}'}{\Delta \xi} \\
& = \lim_{\Delta \xi \rightarrow 0} \frac{\begin{bmatrix} [\Delta \mathbf{w}]_{\times} & \Delta \mathbf{v} \\ \mathbf{0}^{\intercal} & 0 \end{bmatrix} \begin{bmatrix} \tilde{\mathbf{X}}' \\ 1 \end{bmatrix}}{\Delta \xi} \\
& = \lim_{\Delta \xi \rightarrow 0} \frac{\begin{bmatrix} [\Delta \mathbf{w}]_{\times} \tilde{\mathbf{X}}' + \Delta \mathbf{v} \\ \mathbf{0}^{\intercal} \end{bmatrix}}{[\Delta \mathbf{w}, \Delta \mathbf{v}]^{\intercal}}  = \begin{bmatrix} -[\tilde{\mathbf{X}}']_{\times} & \mathbf{I}  \\ \mathbf{0}^{\intercal} & \mathbf{0}^{\intercal} \end{bmatrix}  \in \mathbb{R}^{4 \times 6}
 \end{aligned} } \end{equation}

 

Therefore, when using the $[2]$ perturbation model, there is an advantage in that the Jacobian can be obtained simply by using the skew-symmetric matrix of the points $\mathbf{X}'$ in the 3D space.  In the case of photometric error optimization, since most of the errors for the brightness change of sequentially incoming images are optimized, the camera pose change is not large and the size of $\Delta \xi$ is not large, so the above Jacobian is generally used. Since we use the $[2]$ perturbation model, the small increment $\Delta \xi^{*}$ is updated as (\ref{eq:photo2}).

\begin{equation}
  \begin{aligned}
 \mathbf{T} \leftarrow \Delta \mathbf{T}^{*}\mathbf{T}= \exp([\Delta \xi^{*}]_{\times}) \mathbf{T}
\end{aligned} 
\end{equation}

 

In the above equation, the second row is the first-order Taylor approximation applied to the small twist increment $\exp([\Delta \xi]_{\times})$.  To understand the approximation of the second row, the transformation matrix $\mathbf{T}$ is exponential given an arbitrary twist $\xi = [\mathbf{w}, \mathbf{v}]^{\intercal}$ When developed in mapping form, it can be expressed as follows.

\begin{equation}
\begin{aligned}
  \mathbf{T} = \exp([\xi]_{\times}) & =  \mathbf{I} +  \begin{bmatrix} [\mathbf{w}]_{\times} & \mathbf{v} \\ \mathbf{0}^{\intercal} & 0 \end{bmatrix}  + \frac{1}{2!} \begin{bmatrix} [\mathbf{w}]_{\times}^{2} & [\mathbf{w}]_{\times}\mathbf{v} \\ \mathbf{0}^{\intercal} & 0 \end{bmatrix} + \frac{1}{3!} \begin{bmatrix} [\mathbf{w}]_{\times}^{3} & [\mathbf{w}]_{\times}^{2}\mathbf{v} \\ \mathbf{0}^{\intercal} & 0 \end{bmatrix}  + \cdots \\ 
& = \mathbf{I} + [ \xi]_{\times} + \frac{1}{2!} [ \xi]_{\times}^{2} +  \frac{1}{3!} [ \xi]_{\times}^{3} + \cdots
\end{aligned}
\end{equation}

For a small twist increment $\Delta \xi$, it can be approximated as follows by ignoring higher-order terms of the second or higher order.
\begin{equation}
\begin{aligned}
  \exp([\Delta \xi]_{\times}) \approx  \mathbf{I} +  [\Delta \xi]_{\times} 
\end{aligned}
\end{equation}

 

Finally, The Jacobian $\mathbf{J}$ for the pose is:

\begin{equation}
\boxed{
  \begin{aligned}
\mathbf{J} = \frac{\partial \mathbf{e}}{\partial \Delta \xi} & =  \frac{\partial \mathbf{I}}{\partial \mathbf{p}_{2}} \frac{\partial \mathbf{p}_{2}}{\partial \tilde{\mathbf{p}}_{2}} \frac{\partial \tilde{\mathbf{p}}_{2}}{\partial \mathbf{X}'} \frac{\partial \mathbf{X}'}{\partial \Delta \xi}  \\
& = \begin{bmatrix} \nabla \mathbf{I}_{u} & \nabla \mathbf{I}_{v} \end{bmatrix} 
\begin{bmatrix} f & 0 & c_{x} \\ 0 & f & c_{y} \end{bmatrix}
\begin{bmatrix} \frac{1}{Z'} & 0 & \frac{-X'}{Z'^{2}} & 0 \\ 0 & \frac{1}{Z'} & \frac{-Y'}{Z'^{2}}&0\\ 0 & 0 & 0 & 0\end{bmatrix}
\begin{bmatrix} -[\tilde{\mathbf{X}}']_{\times} & \mathbf{I} \\ \mathbf{0}^{\intercal} & \mathbf{0}^{\intercal}  \end{bmatrix} \\
 & = \begin{bmatrix} \nabla \mathbf{I}_{u} & \nabla \mathbf{I}_{v} \end{bmatrix}  \begin{bmatrix} \frac{f}{Z'} & 0 & -\frac{fX}{Z'^{2}} & 0\\ 0 & \frac{f}{Z'} & -\frac{fY}{Z'^{2}} & 0\end{bmatrix}
    \begin{bmatrix} 0 & Z' & -Y' & 1 & 0 & 0 \\ -Z' & 0 & X' & 0 & 1 & 0 \\ Y'& -X'& 0 & 0 & 0 & 1 \\ 0 & 0 & 0&0&0&0\end{bmatrix} \\
    & = \begin{bmatrix} \nabla \mathbf{I}_{u} & \nabla \mathbf{I}_{v} \end{bmatrix}  \begin{bmatrix} -\frac{fX'Y'}{Z'^{2}} & \frac{f(1 + X'^{2})}{Z'^{2}} & -\frac{fY'}{Z'} & \frac{f}{Z'} & 0 & -\frac{fX'}{Z'^{2}} \\
      -\frac{f(1+Y'^{2})}{Z'^{2}} & \frac{fX'Y'}{Z'^{2}} & \frac{fX'}{Z'} & 0 & \frac{f}{Z'} & -\frac{fY'}{Z'^{2}} \end{bmatrix} \in \mathbb{R}^{1 \times 6}
  \end{aligned} }
\end{equation}

At this time, since the last line of $\frac{\partial \mathbf{X}'}{\partial \Delta \xi}$ is always 0, it is sometimes omitted and calculated.

 

4.1.2. Code implementations

 

5. Relative pose error (PGO)

Relative pose error is an error mainly used in pose graph optimization (PGO).  For more information on PGO, refer to [SLAM] Pose Graph Optimization 개념 설명 및 예제 코드 분석 post.

 

NOMENCLATURE of relative pose error

  • $\text{(Node) } \mathbf{x}_{i}  = \begin{bmatrix} \mathbf{R}_{i} & \mathbf{t}_{i} \\ \mathbf{0}^{\intercal} & 1 \end{bmatrix} \in \mathbb{R}^{4\times 4}$
  • $\text{(Edge) } \mathbf{z}_{ij}  = \begin{bmatrix} \mathbf{R}_{ij} & \mathbf{t}_{ij} \\ \mathbf{0}^{\intercal} & 1 \end{bmatrix} \in \mathbb{R}^{4\times 4}$
  • $\hat{\mathbf{z}}_{ij}   = \ \mathbf{x}_{i}^{-1}\mathbf{x}_{j}$ : predicted value
  • $\mathbf{z}_{ij}$ : virtual measurement
  • $\mathbf{x} = [\mathbf{x}_{1}, \cdots, \mathbf{x}_{n}]$: All pose nodes in pose graph
  • $\mathbf{e}_{ij}(\mathbf{x}_{i},\mathbf{x}_{j}) \leftrightarrow \mathbf{e}_{ij}$:For convenience of expression, it is sometimes omitted.
  • $\mathbf{J} = \frac{\partial \mathbf{e}}{\partial \mathbf{x}}$
  • $\oplus$ : operator for composition of two SE(3) families
  • $\text{Log}(\cdot)$: Operator that converts SE(3) to twist $\xi \in \mathbb{R}^{6}$.  For more information on logarithm mapping, refer to this post.

 

Given two nodes $\mathbf{x}_{i} and \mathbf{x}_{j}$ on the Pose graph, the relative pose (=observed value) $\mathbf{z}_{ij}$ newly calculated by the sensor data and the existing known The difference in relative pose (=predicted value) $\hat{\mathbf{z}}_{ij}$ is defined as the relative pose error. (figure: Freiburg univ. Robot Mapping Course).

\begin{equation}
\begin{aligned}
\mathbf{e}_{ij}(\mathbf{x}_{i},\mathbf{x}_{j}) = \mathbf{z}_{ij}^{-1}\hat{\mathbf{z}}_{ij} = \mathbf{z}_{ij}^{-1} \mathbf{x}_{i}^{-1}\mathbf{x}_{j}
\end{aligned}
\end{equation}

 

The process of optimizing the relative pose error is called pose graph optimization (PGO) and is also called the back-end algorithm of graph-based SLAM. Nodes $\mathbf{x}_{i}, \mathbf{x}_{i+1}, and \cdots$, which are sequentially calculated by front-end visual odometry (VO) or lidar odometry (LO), are observed Observed when an edge is connected between two non-sequential nodes $\mathbf{x}_{i}, \mathbf{x}_{j}$ because PGO is not performed because the values ​​and predicted values ​ are identical, but loop closing occurs PGO is performed because the difference between the value and the predicted value occurs.

 

That is, PGO is generally performed when a special situation such as loop closing occurs. When the robot revisits the same place while moving, the loop detection algorithm operates to determine the loop.  At this time, if a loop is detected, the existing node $\mathbf{x}_{i}$ and the node $\mathbf{x}_{j}$ created by revisiting are connected as loop edges, and various matching algorithms (GICP, NDT , etc...) to create observations. These observations are called virtual measurements because they are virtual observations created by a matching algorithm, not actual observations.

 

The relative pose error for all nodes on the pose graph can be defined as follows.

\begin{equation}
  \begin{aligned}
 \mathbf{E}(\mathbf{x}) & =  \arg\min_{\mathbf{x}^{*}} \sum_{i}\sum_{j} \left\| \mathbf{e}_{ij} \right\|^{2} \\
& = \arg\min_{\mathbf{x}^{*}} \sum_{i}\sum_{j} \mathbf{e}_{ij}^{\intercal}\mathbf{e}_{ij} 
  \end{aligned}
\end{equation}

 

$\left\|\mathbf{e}(\mathbf{x}^{*})\right\|^{2}$ that satisfies $\mathbf{E}(\mathbf{x}^{*})$ can be computed iteratively through non-linear least squares.  The optimal state is found by iteratively updating $\mathbf{x}$ in small increments $\Delta \mathbf{x}$. 
\begin{equation}
  \begin{aligned}
    \mathbf{E}(\mathbf{x} + \Delta \mathbf{x}) & = \arg\min_{\mathbf{x}^{*}} \sum_{i}\sum_{j} \left\|\mathbf{e}_{ij}(\mathbf{x}_{i} + \Delta \mathbf{x}_{i},\mathbf{x}_{j} + \Delta \mathbf{x}_{j})\right\|^{2} 
  \end{aligned}
\end{equation}

Strictly speaking, since the state increment $\Delta \mathbf{x}$ is an SE(3) transformation matrix, it is correct to add it to the existing state $\mathbf{x}$ through the $\oplus$ operator, but for convenience of expression $+ $ operator is used.

\begin{equation}
  \begin{aligned}
        \mathbf{e}_{ij}(\mathbf{x}_{i} \oplus \Delta \mathbf{x}_{i},\mathbf{x}_{j} \oplus \Delta \mathbf{x}_{j}) 
\quad \rightarrow \quad\mathbf{e}_{ij}(\mathbf{x}_{i} + \Delta \mathbf{x}_{i},\mathbf{x}_{j} + \Delta \mathbf{x}_{j})
  \end{aligned}
\end{equation}

 

The above equation can be expressed as follows through Taylor's first-order approximation.
\begin{equation}
  \begin{aligned}
\mathbf{e}_{ij}(\mathbf{x}_{i} + \Delta \mathbf{x}_{i},\mathbf{x}_{j} + \Delta \mathbf{x}_{j})  & \approx \mathbf{e}_{ij}(\mathbf{x}_{i} ,\mathbf{x}_{j} ) + \mathbf{J}_{ij} \begin{bmatrix} \Delta \mathbf{x}_{i} \\ \Delta \mathbf{x}_{j} \end{bmatrix} \\ & = \mathbf{e}_{ij}(\mathbf{x}_{i} ,\mathbf{x}_{j} ) + \mathbf{J}_{i}\Delta \mathbf{x}_{i} + \mathbf{J}_{j}\Delta \mathbf{x}_{j} \\
& = \mathbf{e}_{ij}(\mathbf{x}_{i} ,\mathbf{x}_{j} ) + \frac{\partial \mathbf{e}_{ij}}{\partial \mathbf{x}_{i}} \Delta \mathbf{x}_{i} + + \frac{\partial \mathbf{e}_{ij}}{\partial \mathbf{x}_{j}} \Delta \mathbf{x}_{j} 
  \end{aligned} \label{eq:rel14}
\end{equation}

 

\begin{equation}
  \begin{aligned}
    \mathbf{E}(\mathbf{x} + \Delta \mathbf{x}) & \approx \arg\min_{\mathbf{x}^{*}} \sum_{i}\sum_{j} \left\|\mathbf{e}_{ij}(\mathbf{x}_{i} + \Delta \mathbf{x}_{i},\mathbf{x}_{j} + \Delta \mathbf{x}_{j}) + \mathbf{J}_{ij} \begin{bmatrix} \Delta \mathbf{x}_{i} \\ \Delta \mathbf{x}_{j} \end{bmatrix} \right\|^{2} \\
  \end{aligned}
\end{equation}

 

By differentiating this, the optimal value of increment $\Delta \mathbf{x}^{*}$ for all nodes is obtained as follows.  The detailed derivation process is omitted in this section.  If you want to know more about the induction process, you can refer to the previous section.
\begin{equation}
  \begin{aligned}
    & \mathbf{J}^{\intercal}\mathbf{J} \Delta \mathbf{x}^{*} = -\mathbf{J}^{\intercal}\mathbf{e} \\ 
    & \mathbf{H}\Delta \mathbf{x}^{*} = - \mathbf{b} \\
  \end{aligned} \label{eq:rel6}
\end{equation}

 

Since the above equation is in the form of a linear system $\mathbf{Ax} = \mathbf{b}$, various linear algebra techniques such as schur complement and cholesky decomposition can be used to find $\Delta \mathbf{x}^{*}$ .  The optimal increment obtained in this way is added to the current state. At this time, whether to update the pose seen in the local coordinate system (right) or the pose seen in the global coordinate system (left) depends on whether the existing $\mathbf{x}$ is multiplied to the right or to the left. will lose  Since the relative pose error is related to the relative pose of the two nodes, a right multiplication that updates in the local coordinate system is applied.
\begin{equation}
  \begin{aligned}
    \mathbf{x} \leftarrow  \mathbf{x} \oplus \Delta \mathbf{x}^{*}
  \end{aligned} 
\end{equation}

 

The definition of the right multiplication $\oplus$ operation is as follows.

\begin{equation}
  \begin{aligned}
 \mathbf{x} \oplus \Delta \mathbf{x}^{*}& = \mathbf{x}  \Delta \mathbf{x}^{*} \\& = \mathbf{x}  \exp([\Delta \xi^{*}]_{\times})  \quad \cdots \text{ locally updated (right mult)} \end{aligned} \label{eq:rel2}
\end{equation}

 

 

5.1. Jacobian of relative pose error

To perform (\ref{eq:rel6}), the Jacobian $\mathbf{J}$ for the relative pose error must be obtained.  Given two non-sequential nodes $\mathbf{x}_{i}, \mathbf{x}_{j}$, the Jacobian $\mathbf{J}_{ij}$ can be expressed as there is.

\begin{equation}
  \begin{aligned}
    \mathbf{J}_{ij} & = \frac{\partial \mathbf{e}_{ij}}{\partial \mathbf{x}_{ij}} \\ & =  \frac{\partial \mathbf{e}_{ij}}{\partial [\mathbf{x}_{i}, \mathbf{x}_{j}]}  \\ & = [\mathbf{J}_{i}, \mathbf{J}_{j}]
  \end{aligned}
\end{equation}

 

Here's a closer look at this:

\begin{equation}
  \begin{aligned}
\mathbf{J}_{ij} = \frac{\partial \mathbf{e}_{ij}}{\partial [\mathbf{x}_{i}, \mathbf{x}_{j}]} & = \frac{\partial }{\partial [\mathbf{x}_{i}, \mathbf{x}_{j}]} \bigg( \mathbf{z}_{ij}^{-1} \hat{\mathbf{z}}_{ij} \bigg) \\ & = \frac{\partial }{\partial [\mathbf{R}_{i}, \mathbf{t}_{i}, \mathbf{R}_{j}, \mathbf{t}_{j}]} \bigg( \mathbf{z}_{ij}^{-1} \hat{\mathbf{z}}_{ij} \bigg) \\
  \end{aligned}
\end{equation}

 

5.1.1. Lie theory-based SE(3) optimization

When obtaining the above Jacobian, the position-related term $\mathbf{t}$ is a 3-dimensional vector and the magnitude of the vector is equal to 3 degrees of freedom, which is the minimum degree of freedom for expressing a 3-dimensional position. constraints do not exist. On the other hand, the rotation matrix $\mathbf{R}$ has 9 parameters, which is more than 3 degrees of freedom, which is the minimum degree of freedom for expressing 3D rotation, so various constraints exist.  This is said to be over-parameterized.  Disadvantages of over-parameterized representation are as follows.

  • Since redundant parameters must be calculated, the amount of computation increases during optimization.
  • The additional degrees of freedom can lead to numerical instability problems.
  • Whenever a parameter is updated, it must always be checked whether the constraint is satisfied.

 

Therefore, a lie theory-based optimization method, which is a minimal parameter expression free from constraints, is generally used. Instead of calculating $\Delta \mathbf{T}^{*}$, which includes a nonlinear rotation matrix, the lie group SE(3)-based optimization method includes $\mathbf{R} \rightarrow \mathbf{w} $, and position-related terms are changed to $\mathbf{t} \rightarrow \mathbf{v}$ to find the optimal lie algebra se(3) $\Delta \xi^{*}$, and then exponential mapping Indicates how to update to SE(3).

\begin{equation}
  \begin{aligned}
    \begin{bmatrix} \Delta \mathbf{x}_{i}^{*}, \Delta \mathbf{x}_{j}^{*} \end{bmatrix}  \rightarrow [\Delta \xi_{i}^{*}, \Delta \xi_{j}^{*}] 
  \end{aligned}
\end{equation}

 

The Jacobian for $\xi$ is

\begin{equation}
  \begin{aligned}
   \mathbf{J}_{ij} & = \frac{\partial \mathbf{e}_{ij}}{\partial [\mathbf{x}_{i}, \mathbf{x}_{j}]}  && \rightarrow  \frac{\partial \mathbf{e}_{ij}}{\partial [\xi_{i}, \xi_{j}]} 
  \end{aligned}
\end{equation}

 

Through this, the existing expression is changed as follows.

\begin{equation}
  \begin{aligned}
    \mathbf{e}_{ij}(\mathbf{x}_{i}, \mathbf{x}_{j}) \quad \quad & \rightarrow \quad \quad \mathbf{e}_{ij}(\xi_{i}, \xi_{j}) \\
    \mathbf{E}(\mathbf{x}) \quad \quad & \rightarrow \quad \quad \mathbf{E}(\xi) \\
    \mathbf{e}_{ij}(\mathbf{x}_{i}, \mathbf{x}_{j}) + \mathbf{J}_{i}' \Delta \mathbf{x}_{i} +  \mathbf{J}_{j}' \Delta \mathbf{x}_{j}  \quad \quad & \rightarrow \quad \quad \mathbf{e}_{ij}(\xi_{i}, \xi_{j}) + \mathbf{J}_{i}\Delta \xi_{i} + \mathbf{J}_{j}\Delta \xi_{j}   \\
    \mathbf{H}\Delta\mathbf{x}^{*} = -\mathbf{b} \quad \quad & \rightarrow \quad \quad \mathbf{H}\Delta \xi^{*}  = -\mathbf{b} \\
\mathbf{x} \leftarrow \Delta \mathbf{x}^{*}\mathbf{x} \quad \quad & \rightarrow \quad \quad \mathbf{x} \leftarrow \exp([\Delta \xi^{*}]_{\times}) \mathbf{x} 
  \end{aligned}
\end{equation}

- $\mathbf{J}_{ij}'  = \frac{\partial \mathbf{e}}{\partial [\mathbf{x}_{i}, \mathbf{x}_{j}]}$

- $\mathbf{J}_{ij}  = \frac{\partial \mathbf{e}}{\partial [\xi_{i}, \xi_{j}]} $

 

$\exp([\xi]_{\times}) \in \text{SE}(3)$ refers to an operation that transforms twist $\xi$ into a 3D pose by exponential mapping.  For more information on exponential mapping, refer to this link.

\begin{equation}
  \begin{aligned}
    \exp([\Delta \xi]_{\times}) = \Delta \mathbf{x} 
  \end{aligned}
\end{equation}

 

$\frac{\partial }{\partial \xi}( \mathbf{z}_{ij}^{-1} \hat{\mathbf{z}}_{ij})$ is $\mathbf{z}_{ij}^{-1} Since it is not immediately visible in \hat{\mathbf{z}}_{ij}$, you need to change it to a term related to lie algebra.

\begin{equation}
  \begin{aligned}
\mathbf{z}_{ij}^{-1}\hat{\mathbf{z}}_{ij} & \rightarrow \text{Log}(\mathbf{z}_{ij}^{-1}\hat{\mathbf{z}}_{ij}) 
  \end{aligned}
\end{equation}

 

At this time, $\text{Log}(\cdot)$ means logarithm mapping that changes from SE(3) to twist $\xi \in \mathbb{R}^{6}$.  For more information on logarithm mapping, refer to this post .  Therefore, the SE(3) version relative pose error $\mathbf{e}_{ij}(\xi_{i}, \xi_{j})$ is changed as follows.

\begin{equation}
 \boxed{ \begin{aligned}
\mathbf{e}_{ij}(\xi_{i}, \xi_{j})& = \text{Log}(\mathbf{z}_{ij}^{-1}\hat{\mathbf{z}}_{ij}) 
  \end{aligned} }  \label{eq:rel22}
\end{equation}

 

Here's how to break it down in detail:

\begin{equation}
  \begin{aligned}
\mathbf{e}_{ij}(\xi_{i}, \xi_{j}) & = \text{Log}(\mathbf{z}_{ij}^{-1}\hat{\mathbf{z}}_{ij}) \\ & = \text{Log}(\mathbf{z}_{ij}^{-1}\mathbf{x}_{i}^{-1}\mathbf{x}_{j}) \\ & = \text{Log}(\exp([-\xi_{ij}]_{\times})\exp([-\xi_{i}]_{\times})\exp([\xi_{j}]_{\times}))
  \end{aligned}
\end{equation}

 

Looking at the above expression, you can see that $\xi_{i}$ and $\xi_{j}$ parameters in $\mathbf{z}_{ij}$ are connected by exponential mapping.  Applying the left perturbation model to the formula in the second line of the above equation to express the incremental amount is as follows.

\begin{equation}
  \begin{aligned}
\mathbf{e}_{ij}(\xi_{i} + \Delta \xi_{i}, \xi_{j} + \Delta \xi_{j}) & = \text{Log}(\hat{\mathbf{z}}_{ij}^{-1}\mathbf{x}_{i}^{-1}\exp(-[\Delta \xi_{i}]_{\times})\exp([\Delta \xi_{j}]_{\times})\mathbf{x}_{j})
  \end{aligned} \label{eq:rel10}
\end{equation}

 

In the above equation, the terms are arranged in the form of $\mathbf{e} + \mathbf{J}\Delta\xi$ by moving the increment term to the left or right.  To do this, we need to use the following property of the adjoint matrix of SE(3).  For more information on Adjoint martix, refer to the this post.

\begin{equation}
  \begin{aligned}
\exp([\text{Ad}_{\mathbf{T}} \cdot \xi]_{\times}) = \mathbf{T} \cdot \exp([\xi]_{\times}) \cdot \mathbf{T}^{-1}
  \end{aligned}
\end{equation}

 

The expression above is transformed into an expression for $\mathbf{T} \rightarrow \mathbf{T}^{-1}$ as follows.

\begin{equation}
  \begin{aligned}
\exp([\text{Ad}_{\mathbf{T}^{-1}} \cdot \xi]_{\times}) = \mathbf{T}^{-1} \cdot \exp([\xi]_{\times}) \cdot \mathbf{T}
  \end{aligned}
\end{equation}

 

And rearranging, we get the following formula:

\begin{equation}
  \begin{aligned}
 \exp([\xi]_{\times}) \cdot \mathbf{T} = \mathbf{T} \exp([\text{Ad}_{\mathbf{T}^{-1}} \cdot \xi]_{\times})
  \end{aligned} \label{eq:rel11}
\end{equation}

 

(\ref{eq:rel11}) moves the $\exp(\cdot)\exp(\cdot)$ term in the middle of (\ref{eq:rel10}) to the right or left.  This post explains the process of moving to the right.  If this is expanded by $\Delta \xi_{i}$ and $\Delta \xi_{j}$ respectively, it is as follows.

\begin{equation}
  \begin{aligned}
\mathbf{e}_{ij}(\xi_{i} + \Delta \xi_{i}, \xi_{j}) & = \text{Log}(\hat{\mathbf{z}}_{ij}^{-1}\mathbf{x}_{i}^{-1}\exp(-[\Delta \xi_{i}]_{\times}) \mathbf{x}_{j}) \\ &= \text{Log}(\mathbf{z}_{ij}^{-1}\mathbf{x}_{i}^{-1}\mathbf{x}_{j} \exp([-\text{Ad}_{\mathbf{x}_{j}^{-1}}\Delta \xi_{i}]_{\times})) \quad \cdots \text{[1]} \\
\mathbf{e}_{ij}(\xi_{i}, \xi_{j} + \Delta \xi_{j}) & = \text{Log}(\hat{\mathbf{z}}_{ij}^{-1}\mathbf{x}_{i}^{-1}\exp([\Delta \xi_{j}]_{\times})\mathbf{x}_{j}) \\ &= \text{Log}(\mathbf{z}_{ij}^{-1}\mathbf{x}_{i}^{-1}\mathbf{x}_{j} \exp([\text{Ad}_{\mathbf{x}_{j}^{-1}}\Delta \xi_{j}]_{\times})) \quad \cdots \text{[2]}
  \end{aligned} \label{eq:rel21}
\end{equation}

 

In order to simplify this expression, $[1]$ and $[2]$ are respectively expressed as follows.

\begin{equation}
  \begin{aligned}
 \text{Log}( \exp([\mathbf{a}]_{\times}) \exp([\mathbf{b}]_{\times})) \quad \cdots \text{[1]} \\
 \text{Log}( \exp([\mathbf{a}]_{\times}) \exp([\mathbf{c}]_{\times})) \quad \cdots \text{[2]}
  \end{aligned} \label{eq:rel13}
\end{equation}

  • $\exp([\mathbf{a}]_{\times}) = \mathbf{z}_{ij}^{-1}\mathbf{x}_{i}^{-1}\mathbf{x}_{j}$:Transformation matrix expressed in exponential terms.
    • According to the definition of (\ref{eq:rel22}) above, $\mathbf{a} = \mathbf{e}_{ij}(\xi_{i},  \xi_{j})$.
  • $\mathbf{b} = -\text{Ad}_{\mathbf{x}_{j}^{-1}}\Delta \xi_{i}$
  • $\mathbf{c} = \text{Ad}_{\mathbf{x}_{j}^{-1}}\Delta \xi_{j}$

 

The above equation can be rearranged using the right-hand BCH approximation.  The right BCH approximation is

\begin{equation}
  \begin{aligned}
    \exp([\xi]_{\times})\exp([\Delta \xi]_{\times}) & = \exp([\xi + \mathcal{J}^{-1}_{r}\Delta \xi]_{\times}) \\
    \exp([\xi + \Delta \xi]_{\times}) & = \exp([\xi]_{\times}) \exp([\mathcal{J}_{r}\Delta \xi]_{\times})\\
  \end{aligned} 
\end{equation}

 

For more information, please refer to Chapter 4 of Introduction to Visual SLAM.  By using the BCH approximation, (\ref{eq:rel13}) is summarized as follows.

\begin{equation}
  \begin{aligned} 
\text{Log}(\exp([\mathbf{a}]_{\times}) \exp([\mathbf{b}]_{\times}) ) & = \text{Log}(\exp([\mathbf{a} + \mathcal{J}^{-1}_{r}\mathbf{b}]_{\times})) \\ & = \mathbf{a} + \mathcal{J}^{-1}_{r}\mathbf{b} \quad \cdots \text{[1]} \\
\text{Log}(\exp([\mathbf{a}]_{\times}) \exp([\mathbf{c}]_{\times}) ) & = \text{Log}(\exp([\mathbf{a} + \mathcal{J}^{-1}_{r}\mathbf{c}]_{\times})) \\ & = \mathbf{a} +  \mathcal{J}^{-1}_{r}\mathbf{c} \quad \cdots \text{[2]}
  \end{aligned}
\end{equation}

 

Finally, after solving the substitution and rewriting the $\Delta \xi_{i}$ and $\Delta \xi_{j}$ expressions, the SE(3) version formula of (\ref{eq:rel14}) is obtained.

\begin{equation}
 \boxed{ \begin{aligned}
\mathbf{e}_{ij}(\xi_{i} + \Delta \xi_{i}, \xi_{j} + \Delta \xi_{j}) & = \mathbf{a} + \mathcal{J}^{-1}_{r}\mathbf{b} + \mathcal{J}^{-1}_{r}\mathbf{c} \\& = \mathbf{e}_{ij}(\xi_{i} , \xi_{j} ) -  \mathcal{J}^{-1}_{r}\text{Ad}_{\mathbf{x}_{j}^{-1}}\Delta \xi_{i} + \mathcal{J}^{-1}_{r}\text{Ad}_{\mathbf{x}_{j}^{-1}}\Delta \xi_{j} \\ &  = \mathbf{e}_{ij}(\xi_{i} , \xi_{j} ) + \frac{\partial \mathbf{e}_{ij} }{\partial \Delta \xi_{i}} \Delta \xi_{i} + \frac{\partial \mathbf{e}_{ij} }{\partial \Delta \xi_{j}} \Delta \xi_{j}
  \end{aligned} }
\end{equation}

 

Therefore, the SE(3) version Jacobian of the final relative pose error is as follows.

\begin{equation}
 \boxed{ \begin{aligned}
 & \frac{\partial \mathbf{e}_{ij} }{\partial \Delta \xi_{i}} = -\mathcal{J}^{-1}_{r}\text{Ad}_{\mathbf{x}_{j}^{-1}} \in \mathbb{R}^{6\times6} \\
& \frac{\partial \mathbf{e}_{ij} }{\partial \Delta \xi_{j}} = \mathcal{J}^{-1}_{r}\text{Ad}_{\mathbf{x}_{j}^{-1}} \in \mathbb{R}^{6\times6}
  \end{aligned} }
\end{equation}

 

At this time, since $\mathcal{J}^{-1}_{r}$ is a complicated expression, it is generally used by approximating it as follows, or it is used by setting it as $\mathbf{I}_{6}$ .

\begin{equation}
  \begin{aligned}
 \mathcal{J}^{-1}_{r} \approx \mathbf{I}_{6} + \frac{1}{2} \begin{bmatrix} [\mathbf{w}]_{\times} & [\mathbf{v}]_{\times} \\ \mathbf{0} & [\mathbf{w}]_{\times} \end{bmatrix} \in \mathbb{R}^{6\times6}
  \end{aligned} 
\end{equation}

 

If $\mathcal{J}^{-1}_{r} = \mathbf{I}_{6}$ and optimization is performed, there is a reduction in the amount of computation, but the optimization performance is similar to the above Jacobian. The method used has a slight predominance.  For more information, please refer to Chapter 11 of Introduction to Visual SLAM.

 

5.1.2. Code implementations

  • g2o code: edge_se3_expmap.cpp#L55  
    • In the g2o code above, the error is $\mathbf{e}_{ij}=\mathbf{x}_{j}^{-1}\mathbf{z}_{ij}\mathbf{x}_{i}$ , which makes the Jacobian slightly different from the description above.
    • $\frac{\partial \mathbf{e}_{ij} }{\partial \Delta \xi_{i}} = \mathcal{J}^{-1}_{l}\text{Ad}_{\mathbf{x}_{j}^{-1}\mathbf{z}_{ij}}$
    • $\frac{\partial \mathbf{e}_{ij} }{\partial \Delta \xi_{j}} = -\mathcal{J}^{-1}_{r}\text{Ad}_{\mathbf{x}_{i}^{-1}\mathbf{z}_{ij}^{-1}}$
    • This is the same format as in the (\ref{eq:rel21}) expression where $\Delta \xi_{i}$  is arranged by passing terms to the left, and $\Delta \xi_{j}$ is arranged by passing terms to the right and merged.
    • It also seems to be an approximate value for $\mathcal{J}^{-1}_{l} \approx \mathbf{I}_{6}, \mathcal{J}^{-1}_{r} \approx \mathbf{I}_{6}$.  Therefore, the actual implemented code is as follows.
      • $\frac{\partial \mathbf{e}_{ij} }{\partial \Delta \xi_{i}} \approx \text{Ad}_{\mathbf{x}_{j}^{-1}\mathbf{z}_{ij}}$
      • $\frac{\partial \mathbf{e}_{ij} }{\partial \Delta \xi_{j}} \approx -\text{Ad}_{\mathbf{x}_{i}^{-1}\mathbf{z}_{ij}^{-1}}$

 

 

6. Line reprojection error

Line reprojection error is an error used when optimizing a line in 3D space expressed in plücker coordinates.  For more information on Plücker coordinates, see the Plücker Coordinate 개념 정리 post.

 

 

NOMENCLATURE of line reprojection error

  • $\mathcal{T}_{cw} \in \mathbb{R}^{6\times6}$: Transformation matrix of Plücker lines
  • $\mathcal{K}_{L}$: line intrinsic matrix
  • $\mathbf{U} \in SO(3)$: Rotation matrix of a 3D line
  • $\mathbf{W} \in SO(2)$: A matrix containing information on the distance a 3D line is from the origin
  • $\boldsymbol{\theta} \in \mathbb{R}^{3}$:  Parameter corresponding to rotation matrix SO(3) 
  • $\theta \in \mathbb{R}$:  Parameter corresponding to rotation matrix SO(2)
  • $\mathbf{u}_{i}$: $i$th column vector
  • $\mathcal{X} = [\delta_{\boldsymbol{\theta}}, \delta_\xi ]$: State variable
  • $\delta_{\boldsymbol{\theta}} = [ \boldsymbol{\theta}^{\intercal}, \theta ] \in \mathbb{R}^{4}$: State variables in orthonormal representation
  • $\delta_{\xi} = [\delta \xi] \in se(3)$: For the update method through Lie theory, refer to this link
  • $\oplus$ : An operator that can update the state variable $\delta_{\boldsymbol{\theta}}, \delta_\xi$  in one step.
  • $\mathbf{J} = \frac{\partial \mathbf{e}_{l}}{\partial \mathcal{X}} = \frac{\partial \mathbf{e}_{l}}{\partial [\delta_{\boldsymbol{\theta}}, \delta_\xi]}$

 

 

A line in 3D space can be expressed as a 6D column vector using Plücker coordinates.

\begin{equation}
  \begin{aligned}
     \mathcal{L} & = [\mathbf{m}^{\intercal} : \mathbf{d}^{\intercal}]^{\intercal} = [ m_{x} : m_{y} : m_{z} : d_{x} : d_{y} : d_{z}]^{\intercal}
  \end{aligned}
\end{equation}

 

Unlike the $[\mathbf{d} : \mathbf{m}]$ order described above, most papers using Plücker Coordinate use the $[\mathbf{m} : \mathbf{d}]$ order, so this section Also,  lines are expressed in the corresponding order. Since the linear expression method has scale ambiguity, it has 5 degrees of freedom, and even if $\mathbf{m}$ and $\mathbf{d}$ are not unit vectors, a line can be uniquely expressed by the ratio of the values ​​of the two vectors.

 

6.1. Line Transformation and projection

If $\mathcal{L}_{w}$ is a line viewed from the world coordinate system, it can be converted as follows when viewed from the camera coordinate system.

\begin{equation}
  \begin{aligned}
     \mathcal{L}_{c} & = \begin{bmatrix} \mathbf{m}_{c} \\ \mathbf{d}_{c} \end{bmatrix} = \mathcal{T}_{cw}\mathcal{L}_{w} = \begin{bmatrix} \mathbf{R}_{cw} & \mathbf{t}^{\wedge}\mathbf{R}_{cw} \\ 0 & \mathbf{R}_{cw} \end{bmatrix} \begin{bmatrix} \mathbf{m}_{w} \\ \mathbf{d}_{w} \end{bmatrix}
  \end{aligned}
\end{equation}

- $\mathcal{T}_{cw} \in \mathbb{R}^{6\times6}$:Transformation matrix for the  Plücker line 

 

Projecting the line onto the image plane gives:

\begin{equation}
  \begin{aligned}
     l_{c}  & = \begin{bmatrix} l_{1} \\ l_{2} \\ l_{3} \end{bmatrix} = \mathcal{K}_{L}\mathbf{m}_{c} = \begin{bmatrix} f_{y} && \\ &f_{x} & \\ -f_{y}c_{x} & -f_{x}c_{y} & f_{x}f_{y} \end{bmatrix} \begin{bmatrix} m_{x} \\ m_{y} \\ m_{z} \end{bmatrix}
  \end{aligned}
\end{equation}

- $\mathcal{K}_{L}$: 직선의 내부 파라미터 행렬(line intrinsic matrix)

 

$\mathcal{K}_{L}$ means  $\mathcal{P} = [\det(\mathbf{N}) \mathbf{N}^{-\intercal} | \mathbf{n}^{\wedge} \mathbf{N} ]$  to $\mathbf{P} = K [ \mathbf{I} | \mathbf{0}]$.  So $\mathcal{P} = [\det(\mathbf{K})\mathbf{K}^{-\intercal} |  \mathbf{0}]$, so the $\mathbf{d}$ term of $\mathcal{L}$ is cleared to 0.  Therefore, when $\mathbf{K} = \begin{bmatrix} f_x & & c_x \\ & f_y & c_y \\ &&1 \end{bmatrix}$, the following expression is derived.

\begin{equation}
  \begin{aligned}
    \mathcal{K}_{L} = \det(\mathbf{K})\mathbf{K}^{-\intercal} = \begin{bmatrix} f_{y} && \\ &f_{x} & \\ -f_{y}c_{x} & -f_{x}c_{y} & f_{x}f_{y} \end{bmatrix} \in \mathbb{R}^{3\times3}
  \end{aligned}
\end{equation}

 

6.2. Line reprojection error

The reprojection error $\mathbf{e}_{l}$ of a line can be expressed as follows.

\begin{equation}
  \begin{aligned}
     \mathbf{e}_{l} = \begin{bmatrix} d_{s}, \ d_{e} \end{bmatrix}= \begin{bmatrix} \frac{\mathbf{x}_{s}^{\intercal}l_{c}}{\sqrt{l_{1}^{2} + l_{2}^{2}}},  & \frac{\mathbf{x}_{e}^{\intercal}l_{c}}{\sqrt{l_{1}^{2} + l_{2}^{2}}}\end{bmatrix} \in \mathbb{R}^{2}
  \end{aligned}
\end{equation}

 

This can be expressed through the formula for the distance between a point and a line.  At this time, $\{\mathbf{x}_{s}$ and $\mathbf{x}_{e}\}$ mean the start and end points of the line extracted using line feature extracture (e.g., LSD), respectively. .  In other words, $\mathcal{l}_{c}$ is the predicted value obtained through modeling, and the line connecting $\mathbf{x}_{s}$ and $\mathbf{x}_{e}$ is measured through sensor data. becomes an observation.

 

6.3. Orthonormal representation

A problem arises if the Plücker Coordinate expression is used as it is when BA optimization is performed using $\mathbf{e}_{l}$ obtained above.  Since the Plücker Coordinate always has 5 degrees of freedom because it must satisfy the Klein quadric constraint of $\mathbf{m}^{\intercal}\mathbf{d} = 0$, the minimum number of parameters that can express a line is 4 It is over-parameterized.  The disadvantages of the over-parameterized expression method are as follows.

  • Since redundant parameters must be calculated, the amount of computation increases during optimization.
  • The additional degrees of freedom can lead to numerical instability problems.
  • Whenever a parameter is updated, it must always be checked whether the constraint is satisfied.

 

Therefore, when optimizing a line, an orthonormal expression is generally used to change the minimum parameter to four degrees of freedom.  In other words, when expressing a line, Plücker Coordinate is used, but when performing optimization, it transforms into orthonormal expression, updates the optimal value, and returns to Plücker Coordinate.

 

Orthonormal expression is as follows.  A line in 3D space can always be expressed as:

\begin{equation}
  \begin{aligned}
     (\mathbf{U}, \mathbf{W}) \in SO(3) \times SO(2)
  \end{aligned}
\end{equation}

 

Any Plücker line $\mathcal{L} = [\mathbf{m}^{\intercal} : \mathbf{d}^{\intercal}]^{\intercal}$ always has a one-to-one correspondence $(\mathbf{U}, \mathbf{W})$, and this representation method is called orthonormal representation.  Given a line $\mathcal{L}_{w} = [ \mathbf{m}_{w}^{\intercal} : \mathbf{d}_{w}^{\intercal}]^{\intercal}$ in the world, $(\mathbf{U}, \mathbf{W})$ can be obtained by performing QR decomposition of $\mathcal{L}_{w}$.

\begin{equation}
  \begin{aligned}
     \begin{bmatrix} \mathbf{m}_{w} \ | \ \mathbf{d}_{w}  \end{bmatrix}= \mathbf{U} \begin{bmatrix} w_{1} & 0\\ 0& w_{2} \\0 & 0 \end{bmatrix}, \quad \text{with set: } \mathbf{W} = \begin{bmatrix} w_{1} & -w_{2} \\ w_{2} & w_{1} \end{bmatrix}
  \end{aligned}
\end{equation}

 

At this time, the element $(1,2)$ of the upper triangle matrix $\mathbf{R}$ always becomes 0 due to the Plücker constraint (Klein quadric).  Since $\mathbf{U}$ and $\mathbf{W}$ mean 3D and 2D rotation matrices, respectively, $\mathbf{U} = \mathbf{R}(\boldsymbol{\theta}), \mathbf{W } = \mathbf{R}(\theta)$.

\begin{equation}
  \begin{aligned}
     \mathbf{R}(\boldsymbol{\theta}) & = \mathbf{U} = \begin{bmatrix} \mathbf{u}_{1} & \mathbf{u}_{2} & \mathbf{u}_{3} \end{bmatrix} = \begin{bmatrix} \frac{\mathbf{m}_{w}}{\left\| \mathbf{m}_{w} \right\|} &  \frac{\mathbf{d}_{w}}{\left\| \mathbf{d}_{w} \right\|} &  \frac{\mathbf{m}_{w} \times \mathbf{d}_{w}}{\left\| \mathbf{m}_{w} \times \mathbf{d}_{w} \right\|} \end{bmatrix} \\ 
\mathbf{R}(\theta) & = \mathbf{W} =  \begin{bmatrix} w_{1} & -w_{2} \\ w_{2} & w_{1} \end{bmatrix} =  \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix} \\ 
& = \frac{1}{\sqrt{\left\| \mathbf{m}_{w} \right\|^{2} + \left\| \mathbf{d}_{w} \right\|^{2}}} \begin{bmatrix} \left\| \mathbf{m}_{w} \right\|  & \left\| \mathbf{d}_{w} \right\|  \\ -\left\| \mathbf{d}_{w} \right\| & \left\| \mathbf{m}_{w} \right\| \end{bmatrix}
\end{aligned}
\end{equation}

 

When performing real optimizations, they are updated like $\mathbf{U} \leftarrow \mathbf{U}\mathbf{R}(\boldsymbol{\theta}), \mathbf{W} \leftarrow \mathbf{W}\mathbf{R}(\theta)$.  So the orthonormal representation is a  line in 3D space $\delta_{\boldsymbol{\theta}} = [ \boldsymbol{\theta}^{\intercal}, \theta ] \in \mathbb{R}^{4}$ can be expressed with four degrees of freedom.  $[ \boldsymbol{\theta}^{\intercal}, \theta ]$ updated through optimization is converted to $\mathcal{L}_{w}$ as follows.

\begin{equation}
  \begin{aligned}
    \mathcal{L}_{w} = \begin{bmatrix} w_{1} \mathbf{u}_{1}^{\intercal} & w_{2} \mathbf{u}_{2}^{\intercal} \end{bmatrix}
\end{aligned}
\end{equation}

 

6.4. Error function formulation

In order to optimize the reprojection error $\mathbf{e}_{l}$ for a line, iteratively using a nonlinear least squares method such as Gauss-Newton (GN) or Levenberg-Marquardt (LM) to find the optimal variable. need to update  The expression of the error function using the reprojection error is as follows.

\begin{equation}
  \begin{aligned}
 \mathbf{E}_{l}(\mathcal{X}) & =  \arg\min_{\mathcal{X}^{*}} \sum_{i}\sum_{j} \left\| \mathbf{e}_{l,ij} \right\|^{2} \\
& = \arg\min_{\mathcal{X}^{*}} \sum_{i}\sum_{j} \mathbf{e}_{l,ij}^{\intercal}\mathbf{e}_{l,ij} \\
  \end{aligned} \label{eq:line10}
\end{equation}

 

The $\left\|\mathbf{e}_{l}(\mathcal{X}^{*})\right\|^{2}$ satisfying $\mathbf{E}_{l}(\mathcal{X}^{*})$ can be calculated iteratively through non-linear least squares. The optimal state is found by iteratively updating $\mathcal{X}$ in small increments $\Delta \mathcal{X}$.
\begin{equation}
  \begin{aligned}
    \mathbf{E}_{l}(\mathcal{X} + \Delta \mathcal{X}) & = \arg\min_{\mathcal{X}^{*}} \sum_{i}\sum_{j} \left\|\mathbf{e}_{l}(\mathcal{X} +\Delta \mathcal{X})\right\|^{2} 
  \end{aligned}
\end{equation}

Strictly speaking, since the state increment $\Delta \mathcal{X}$ includes the SE(3) transformation matrix, it is correct to add it to the existing state $\mathcal{X}$ through the $\oplus$ operator, but for convenience of expression The $+$ operator is used.

\begin{equation}
  \begin{aligned}
        \mathbf{e}_{l}( \mathcal{X} \oplus \Delta \mathcal{X}) 
\quad \rightarrow \quad\mathbf{e}_{l}(\mathcal{X} + \Delta \mathcal{X})
  \end{aligned}
\end{equation}

 

The above equation can be expressed as follows through Taylor's first-order approximation.
\begin{equation}
  \begin{aligned}
\mathbf{e}_{l}(\mathcal{X} + \Delta \mathcal{X})  & \approx \mathbf{e}_{l}(\mathcal{X}) + \mathbf{J}\Delta \mathcal{X} \\ & = \mathbf{e}_{l}(\mathcal{X}) + \mathbf{J}_{\boldsymbol{\theta}} \Delta \delta_{\boldsymbol{\theta}} +\mathbf{J}_{\xi} \Delta \delta_\xi \\
& = \mathbf{e}_{l}(\mathcal{X}) + \frac{\partial \mathbf{e}_{l}}{\partial \delta_{\boldsymbol{\theta}}} \Delta \delta_{\boldsymbol{\theta}} + \frac{\partial \mathbf{e}_{l}}{\partial \delta_\xi}\Delta \delta_\xi \\
  \end{aligned}
\end{equation}

 

\begin{equation}
  \begin{aligned}
    \mathbf{E}_{l}(\mathcal{X} + \Delta \mathcal{X}) & \approx \arg\min_{\mathcal{X}^{*}} \sum_{i}\sum_{j} \left\|\mathbf{e}_{l}(\mathcal{X}) + \mathbf{J}\Delta \mathcal{X} \right\|^{2} \\
  \end{aligned}
\end{equation}

 

By differentiating this, the optimal value of increment $\Delta \mathcal{X}^{*}$ is obtained as follows.  The detailed derivation process is omitted in this section.  If you want to know more about the induction process, you can refer to the previous section.

\begin{equation}
  \begin{aligned}
    & \mathbf{J}^{\intercal}\mathbf{J} \Delta \mathcal{X}^{*} = -\mathbf{J}^{\intercal}\mathbf{e} \\ 
    & \mathbf{H}\Delta \mathcal{X}^{*} = - \mathbf{b} \\
  \end{aligned}
\end{equation}

 

6.4.1. The analytical jacobian of 3d line

As explained in the previous section, to perform nonlinear optimization we need to compute $\mathbf{J}$.  $\mathbf{J}$ consists of:

\begin{equation}
  \begin{aligned}
    & \mathbf{J} = [ \mathbf{J}_{\boldsymbol{\theta}}, \mathbf{J}_{\xi} ] 
  \end{aligned}
\end{equation}

 

$[ \mathbf{J}_{\boldsymbol{\theta}}, \mathbf{J}_{\xi} ]$ can be expanded as follows:

\begin{equation}
  \begin{aligned}
    & \mathbf{J}_{\boldsymbol{\theta}} = \frac{\partial \mathbf{e}_{l}}{\partial \delta_{\boldsymbol{\theta}}} = \frac{\partial \mathbf{e}_{l}}{\partial l} \frac{\partial l}{\partial \mathcal{L}_{c}} \frac{\partial \mathcal{L}_{c}}{\partial \mathcal{L}_{w}} \frac{\partial \mathcal{L}_{w}}{\partial \delta_{\boldsymbol{\theta}}} \\
& \mathbf{J}_{\xi} = \frac{\partial \mathbf{e}_{l}}{\partial \delta_{\xi}} = \frac{\partial \mathbf{e}_{l}}{\partial l} \frac{\partial l}{\partial \mathcal{L}_{c}} \frac{\partial \mathcal{L}_{c}}{\partial \delta_{\xi}}
  \end{aligned}
\end{equation}

 

$\frac{\partial \mathbf{e}_{l}}{\partial l}$ can be obtained as follows.  At this time, note that $l$ is a vector and $l_{i}$ is a scalar.

\begin{equation}
\boxed{ \begin{aligned}
    \frac{\partial \mathbf{e}_{l}}{\partial l}  = \frac{1}{\sqrt{l_{1}^{2} + l_{2}^{2}}} \begin{bmatrix} x_{s} - \frac{l_{1} \mathbf{x}_{s}l}{\sqrt{l_{1}^{2} + l_{2}^{2}}} & y_{s} - \frac{l_{2} \mathbf{x}_{s}l}{\sqrt{l_{1}^{2} + l_{2}^{2}}} & 1 \\
x_{e} - \frac{l_{1} \mathbf{x}_{e}l}{\sqrt{l_{1}^{2} + l_{2}^{2}}} & y_{e} - \frac{l_{2} \mathbf{x}_{e}l}{\sqrt{l_{1}^{2} + l_{2}^{2}}} & 1 \end{bmatrix} \in \mathbb{R}^{2\times3}
  \end{aligned} }
\end{equation}

 

$\frac{\partial l}{\partial \mathcal{L}_{c}}$ can be obtained as follows.

\begin{equation}
  \boxed{ \begin{aligned}
    \frac{\partial l}{\partial \mathcal{L}_{c}} = \frac{\partial \mathcal{K}_{L}\mathbf{m}_{c}}{\partial \mathcal{L}_{c}} = \begin{bmatrix} \mathcal{K}_{L} & \mathbf{0}_{3\times3} \end{bmatrix} = \begin{bmatrix} f_{y} && &   0 &0&0  \\ &f_{x} &  & 0 &0&0 \\ -f_{y}c_{x} & -f_{x}c_{y} & f_{x}f_{y} & 0 &0&0  \end{bmatrix} \in \mathbb{R}^{3\times6}
  \end{aligned} }
\end{equation}

 

$\frac{\partial \mathcal{L}_{c}}{\partial \mathcal{L}_{w}}$ can be obtained as follows.

\begin{equation}
\boxed{  \begin{aligned}
    \frac{\partial \mathcal{L}_{c}}{\partial \mathcal{L}_{w}} = \frac{\partial \mathcal{T}_{cw}\mathcal{L}_{w}}{\partial \mathcal{L}_{w}}= \mathcal{T}_{cw} = \begin{bmatrix} \mathbf{R}_{cw} & \mathbf{t}^{\wedge}\mathbf{R}_{cw} \\ 0 & \mathbf{R}_{cw} \end{bmatrix} \in \mathbb{R}^{6\times6}
  \end{aligned} }
\end{equation}

 

The Jacobian $\frac{\partial \mathcal{L}_{w}}{\partial \delta_{\boldsymbol{\theta}}}$ for the orthonormal representation can be obtained as follows:

\begin{equation}
  \boxed{ \begin{aligned}
    \frac{\partial \mathcal{L}_{w}}{\partial \delta_{\boldsymbol{\theta}}} = \begin{bmatrix} \mathbf{0}_{3\times1}  & -w_{1}\mathbf{u}_{3} & w_{1}\mathbf{u}_{2} &  -w_{2}\mathbf{u}_{1} \\ w_{2}\mathbf{u}_{3} & \mathbf{0}_{3\times1} & -w_{2}\mathbf{u}_{1} & w_{1}\mathbf{u}_{2} \end{bmatrix} \in \mathbb{R}^{6 \times 4}
  \end{aligned} }
\end{equation}

 

The Jacobian $\frac{\partial \mathcal{L}_{c}}{\partial \delta_{\xi}}$ for the camera pose can be obtained as follows:

\begin{equation}
\boxed{  \begin{aligned}
    \frac{\partial \mathcal{L}_{c}}{\partial \delta_{\xi}} = \begin{bmatrix} -(\mathbf{R}\mathbf{m})^{\wedge} - (\mathbf{t}^{\wedge} \mathbf{Rd})^{\wedge} & -(\mathbf{Rd})^{\wedge} \\ -(\mathbf{Rd})^{\wedge} & \mathbf{0}_{3\times3} \end{bmatrix} \in \mathbb{R}^{6 \times 6}
  \end{aligned} }
\end{equation}

 

6.4.2. Code implementations

 

References

[1] [Blog] [SLAM] Bundle Adjustment 개념 리뷰: Reprojection error

[2] [Blog] [SLAM] Optical Flow와 Direct Method 개념  코드 리뷰: Photometric error

[3] [Blog] [SLAM] Pose Graph Optimization 개념 설명  예제 코드 분석: Relative pose error

[4] [Blog] Plücker Coordinate 개념 정리: Line projection error