# False Computation of Reprojection Error in Python Camera Calibration Tutorial

**URL:** <https://forum.opencv.org/t/false-computation-of-reprojection-error-in-python-camera-calibration-tutorial/7981>\
**Category:** Python\
**Tags:** calib3d\
**Created:** [March 17, 2022, 12:58pm UTC](https://forum.opencv.org/t/false-computation-of-reprojection-error-in-python-camera-calibration-tutorial/7981 "2022-03-17T12:58:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ViaAppia](https://avatars.discourse-cdn.com/v4/letter/v/dc4da7/32.png) [@ViaAppia](https://forum.opencv.org/u/ViaAppia)\
**Post date:** [March 17, 2022, 12:58pm UTC](https://forum.opencv.org/t/false-computation-of-reprojection-error-in-python-camera-calibration-tutorial/7981/1 "2022-03-17T12:58:23Z")

</div>

Hello,

i wanted to ask, whether there is an error in the python camera calibration tutorial:  
[https://docs.opencv.org/5.x/dc/dbb/tutorial\_py\_calibration.html](https://docs.opencv.org/5.x/dc/dbb/tutorial_py_calibration.html)

in the very bottom of the webpage the re-projection error is computed in the following way:

```auto
mean_error = 0
for i in range(len(objpoints)):
    imgpoints2, _ = cv.projectPoints(objpoints[i], rvecs[i], tvecs[i], mtx, dist)
    error = cv.norm(imgpoints[i], imgpoints2, cv.NORM_L2)/len(imgpoints2)
    mean_error += error
print( "total error: {}".format(mean_error/len(objpoints)) )

```

I am specifically wondering if the use of the L2 norm is appropriate in this case.  
I have prepared a small minimal example where a=imgpoints[i] (the found chess tile corners) and b = imgpoints2 (the projected imagepoints). the columns of a and b represent the x and y coordinates for 3 total corners:

```auto
import numpy
import cv2

a = np.array([[1.1,1.2],
              [0.3,1.4],
              [1.5,0.6]])

b = np.array([[1,1],
              [0,1],
              [1,0]]).astype(float)

opencv_error = cv2.norm(a, b, cv2.NORM_L2)/3
opencv_numpy_error = np.sqrt(np.sum(np.square(a - b)))/3 #the same implemented in numpy
#sqrt(0.1^2 + 0.2^2 + 0.3^2 + 0.4^2 + 0.5^2 + 0.6^2)/3

mean_error_alternative = np.sum(np.sqrt(np.sum(np.square(a-b),axis = 1)))/3 # this should be the correct computation imo
#(sqrt(0.1^2 + 0.2^2) + sqrt(0.3^2 + 0.4^2) + sqrt(0.5^2 + 0.6^2))/3

print(opencv_error)
print(opencv_numpy_error)
print(mean_error_alternative)

```

My issue is that the l2 norm error (“opencv\_error”) does not actually take into account the 2D differences per corner (sqrt(deltax^2 + deltay^2)), but sums up all individual squared differences. Or is there something I am missing?

Best

ViaAppia

---

<div class="post-metadata">

**Author:** ![Steve\_in\_Denver](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Steve\_in\_Denver](https://forum.opencv.org/u/Steve_in_Denver)\
**Post date:** [March 17, 2022, 2:39pm UTC](https://forum.opencv.org/t/false-computation-of-reprojection-error-in-python-camera-calibration-tutorial/7981/2 "2022-03-17T14:39:11Z")

</div>

The L2 norm should compute the Euclidean distance - are you saying that it does not? Can you include the results of your program (what gets printed for opencv\_error, opencv\_numpy\_error, mean\_error\_alternative?)

---

<div class="post-metadata">

**Author:** ![ViaAppia](https://avatars.discourse-cdn.com/v4/letter/v/dc4da7/32.png) [@ViaAppia](https://forum.opencv.org/u/ViaAppia)\
**Post date:** [March 18, 2022, 10:56am UTC](https://forum.opencv.org/t/false-computation-of-reprojection-error-in-python-camera-calibration-tutorial/7981/3 "2022-03-18T10:56:35Z")

</div>

Dear Steven,  
thank you for your reply!

The printed results of my excectuted code are:  
opencv\_error: 0.31797973380564853  
opencv\_numpy\_error: 0.31797973380564853  
mean\_error\_alternative: 0.5015439217802148

It is computing the Euclidian distance, but it is handling it as if it is computing the error for a 6D problem (sqrt((1.1-1)^2 + (1.2-1)^2 + (0.3-0)^2 + (1.4-1)^2 + (1.5-1)^2 + (0.6-0)^2)/3) and is making no difference between x and y values.  
However, in the example I posted we have only three corners and the re-projection error is defined as the 2D difference between a found point (e.g. x,y = (1.1,1.2)) and projected point (e.g. x,y = (1,1)) which would be sqrt((1.1-1)^2 + (1.2-1)^2) for the first point, which imo has to be repeated for all three point pairs and then averaged.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [March 18, 2022, 1:34pm UTC](https://forum.opencv.org/t/false-computation-of-reprojection-error-in-python-camera-calibration-tutorial/7981/4 "2022-03-18T13:34:56Z")

</div>

`np.linalg.norm` with axis=… argument? then you get a _vector_ of distances.

---

<div class="post-metadata">

**Author:** ![ViaAppia](https://avatars.discourse-cdn.com/v4/letter/v/dc4da7/32.png) [@ViaAppia](https://forum.opencv.org/u/ViaAppia)\
**Post date:** [March 22, 2022, 9:55am UTC](https://forum.opencv.org/t/false-computation-of-reprojection-error-in-python-camera-calibration-tutorial/7981/5 "2022-03-22T09:55:20Z")

</div>

Yes, with np.linalg.norm I can substitute part of my code:  
from:

1. np.sum(np.sqrt(np.sum(np.square(a-b),axis = 1)))/3  
to:
2. np.sum(np.linalg.norm(a-b, axis = 1))/3  
which both yield 0.5015439217802148 as the error.

However the way, the error is computed on [OpenCV: Camera Calibration](https://docs.opencv.org/5.x/dc/dbb/tutorial_py_calibration.html)  
still differs from this approach and yields a different error (0.31797973380564853), which in my opinion makes little sense.

---

<div class="post-metadata">

**Author:** ![darko](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/darko/32/7628_2.png) [@darko](https://forum.opencv.org/u/darko)\
**Post date:** [April 20, 2023, 10:27am UTC](https://forum.opencv.org/t/false-computation-of-reprojection-error-in-python-camera-calibration-tutorial/7981/7 "2023-04-20T10:27:36Z")

</div>

hej, im acutally having the same opinion as you. Im doing my Masterthesis acutally and try to recalculate the cameraCalibration Error. The documentation calculates it wrong.
