When matching feature points of adjacent frames in visual slam, there are thousands of feature points at every turn. Mismatching is inevitable, and mismatching will inevitably affect the accuracy of pose and mapping, so how to distinguish What are the mismatched point pairs? If the homography matrix of two frames is known, assuming that the homography matrix is error-free, then the correct matching feature points in the two frames should be reprojected through the homography matrix. There should be no error or the error is very small, and the error matching The reprojection error of the feature points must be very significant. So can we set an error threshold to identify these mismatch points? But how much should this error threshold be set to?
Assume a feature point in the nth layer of the image pyramid\(\mathbf{p_c}=\begin{bmatrix}u \\ v\end{bmatrix}\) and its corresponding world coordinate system position\(\mathbf{p_w}=\begin{bmatrix}x \\ y \\ z\end{bmatrix}\) span> and the transformation matrix \(T_{cw}\) to reproject the spatial points into the image as \(\mathbf{ p_c’}=\begin{bmatrix}u’ \\ v’\end{bmatrix}\). Then the x-axis reprojection error \(e_x=u-u’\), assuming that there is no error in the transformation matrix, in practice, due to shooting at different times and imaging reasons, it will be Projection error brings noise, so let’s assume \(e_x\sim N(0,\sigma_x^2)\), and similarly assume \(e_y\sim N(0,\sigma_y^2)\) and assume noise variance\(\sigma_x^2=\sigma_y^2=(s^n \times n\_pixels)^2\), \(n\_pixels\) is the number of pixel errors caused by noise, here is 1 , S is the zoom factor of the image pyramid, usually 1.2, there is obvious variance It is related to the layer number of the feature point. This expresses that the higher the number of pyramid levels the feature points are in, the greater the variance of the reprojection error. So there are \(\frac {1}{s^n}e_x\sim N(0,1),\frac {1}{s^n}e_y\sim N(0, 1)\).
Chi-square distribution
If k random variables\(Z_1,Z_2,…,Z_k\ ) are mutually independent random variables conforming to the standard normal distribution (mathematical expectation is 0, variance is 1), then the sum of squares of the random variable Z\(X=\sum_ {i-1}^{k}Z_i^2\) is said to obey the chi-square distribution with k degrees of freedom, denoted as \(X\sim\chi^ 2(k)\).
Order\(Z_1=\frac {1}{s^n}e_x,Z_2=\frac {1}{s^n}e_y,X=Z_1^2+Z_2 ^2\), according to the definition of chi-square distribution, \(X\sim\chi^2(2)\), that is, the card with 2 degrees of freedom Square distribution. For the feature point matched by the binocular, the x coordinate in the right image is \(u_r’\). After reprojection, the x coordinate of the feature point in the left image is calculated.\(u_l\), according to \(disparity d=\frac {baseline b*f_x}{depth}\), The parallax can be calculated to get the x coordinate of the feature point in the right image after reprojection \(u_r=u_l-d\), get \ (e_r=u_r’-u_r\). Similarly, \(\frac {1}{s^n}e_r\sim N(0,1)\) can constitute another degree of freedom of the chi-square distribution, The physical meaning of \(X\) is the sum of the squares of the errors.
The following figure shows the probability density function and cumulative distribution function of the chi-square distribution with different degrees of freedom. The distribution function is recorded as \(F(X\leqslant x)=\alpha \), \(\alpha\) is a probability value, which means that if \(X\)Observe the chi-square distribution, then \(X\) has the probability value of \(\alpha\) \([0,x]\). If the value of \(\alpha\) is known, we can find the corresponding \(x\)< /span> value. For example, the chi-square distribution with 2 degrees of freedom, when \(X\in [0,5.99]\), we are 95% confident that \(X\) obeys the distribution, in order to exclude the feature point when \(X>5.99\).
The figure below is a lookup table of chi-square threshold and corresponding P value, which can be simply considered as \ (P value=1-\alpha\). For specific explanation, please refer to How to understand hypothesis test and P value? .
actual code< /h2>
// openvslam/module/two_view_triangulator.cc:95// chi-squared values for p=5%// (n=2)constexpr float chi_sq_2D = 5.99146;// (n =3)constexpr float chi_sq_3D = 7.81473;Vec2_t reproj_in_cur;float x_right_in_cur;camera->reproject_to_image(rot_cw, trans_cw, pos_w, reproj_in_cur, x_right_proj_in_cur, x_right_proj_curer_t-auto-constant_curin_curer_t = rej_proj_curin_cur); x_right; if ((chi_sq_3D * sigma_sq) <(reproj_err.squaredNorm() + reproj_err_x_right * reproj_err_x_right)) {return false; })else {const Vec2_t reproj_err = reproj_in_curm (keys )) {return false; }}
The above code reproject_to_image is to reproject 3D points back into the image, reproj_err is the above \(\begin{bmatrix} e_x \\ e_y\end{bmatrix}, sigma\_sq=(\frac {1}{s^n})^2 \), reproj_err.squaredNorm()/sigma_sq is \((\frac {1}{s^n})^2(e_x^2+e_y^2)= Z_1^2+Z_2^2=X\sim\chi^2(k)\).
Reference
- [ORB-SLAM2] Chi-squared distribution (Chi-squared) outlier removal
- https ://en.wikipedia.org/wiki/Chi-squared_distribution