# Reprojection Error too High in Visual Odometry

**URL:** <https://forum.opencv.org/t/reprojection-error-too-high-in-visual-odometry/5679>\
**Category:** C++\
**Tags:** calib3d\
**Created:** [October 17, 2021, 5:30pm UTC](https://forum.opencv.org/t/reprojection-error-too-high-in-visual-odometry/5679 "2021-10-17T17:30:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elektron97](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/elektron97/32/3423_2.png) [@Elektron97](https://forum.opencv.org/u/Elektron97)\
**Post date:** [October 17, 2021, 5:30pm UTC](https://forum.opencv.org/t/reprojection-error-too-high-in-visual-odometry/5679/1 "2021-10-17T17:30:53Z")

</div>

Hi everyone! I’m workin on my Mono Visual Odometry project. During the triangulation step, i’m trying to compute the reprojection error. However, the value is too high and I don’t know why.  
This is my function for reprojection error:

```auto
vector<double> reproject_error(Mat world_points, Mat R, Mat t, Mat cameraMatrix, vector<Point2f> img_points)
{

    / ************************REPROJECT ERROR*********************************
     * world_points: Punti 3D in coordinate {W} da proiettare in {C}. *
     * R e t: Trasformazione omogenea che trasforma da {W} a {C} *
     * cameraMatrix *
     * img_points: Punti con cui confrontare i world_points riproiettati. *
     ************************************************************************ /

    //Reproject world_points (3D) in 2D image plan, using projectPoints
    Mat reproject_points;
    Mat Rvec;
    Rodrigues(R, Rvec);

    projectPoints(world_points, Rvec, t, cameraMatrix, noArray(), reproject_points); 

    //Compute reproject error
    vector<double> reproject_err(img_points.size());

    for(int i = 0; i < reproject_point.rows; i++)
    {
        ROS_INFO("Keypoint 2D: [%f, %f] \t Reprojected World Point: [%f, %f]", img_points[i].x, img_points[i].y, reproject_points.at<double>(i, 0), reproject_points.at<double>(i, 1));
        reproject_err[i] = sqrt(pow(img_points[i].x - reproject_point.at<double>(i, 0), 2.0) + pow(img_points[i].y - reproject_points.at<double>(i, 1), 2.0));
    }
    ROS_INFO("----------------------");

    return reproject_err;
}

```

---

<div class="post-metadata">

**Author:** ![Alejandro\_Silvestri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/alejandro_silvestri/32/357_2.png) [@Alejandro\_Silvestri](https://forum.opencv.org/u/Alejandro_Silvestri)\
**Post date:** [October 18, 2021, 3:44am UTC](https://forum.opencv.org/t/reprojection-error-too-high-in-visual-odometry/5679/2 "2021-10-18T03:44:12Z")

</div>

Hi @Elektron97

Code seems fine. I see you don’t provide distortion coefficients, why?  
Remember, errors are in pixel units.  
It is a common mistake to provide the wrong R and t, from camera to world transformation.

---

<div class="post-metadata">

**Author:** ![Elektron97](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/elektron97/32/3423_2.png) [@Elektron97](https://forum.opencv.org/u/Elektron97)\
**Post date:** [October 22, 2021, 9:53am UTC](https://forum.opencv.org/t/reprojection-error-too-high-in-visual-odometry/5679/3 "2021-10-22T09:53:07Z")

</div>

Thank you for your answer.  
For distortion coefficients: I’m working with a simulate camera with 0 distortion coefficients.  
Yes, it’s probabily a wrong usage of triangulatePoints(). Thank you!
