# OpenCV SteoreoCalibration sometimes error, sometimes not

**URL:** <https://forum.opencv.org/t/opencv-steoreocalibration-sometimes-error-sometimes-not/2898>\
**Category:** Uncategorized\
**Tags:** calib3d\
**Created:** [April 21, 2021, 4:13pm UTC](https://forum.opencv.org/t/opencv-steoreocalibration-sometimes-error-sometimes-not/2898 "2021-04-21T16:13:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hans\_HH](https://avatars.discourse-cdn.com/v4/letter/h/ecae2f/32.png) [@Hans\_HH](https://forum.opencv.org/u/Hans_HH)\
**Post date:** [April 21, 2021, 4:13pm UTC](https://forum.opencv.org/t/opencv-steoreocalibration-sometimes-error-sometimes-not/2898/1 "2021-04-21T16:13:09Z")

</div>

Good day dear community,

I am in the process of performing a stereo calibration for two cameras. I know that Stereo calibration will essentially find out the rotation R and translation t between both the cameras. For the two cameras I have given the intrinsic parameters. In the first step, I take about 50 images simultaneously with both cameras. I then finally use these for the stereo calibration. My results also make rough sense. Because I know the distance of the cameras and compared them with the output t and that fits.

However, I sometimes get an error message when I, for example, vary the distance between the cameras and take new pictures, namely:

> (expected: ‘nimages == (int)imagePoints2.total()’), where  
> ‘nimages’ is 27  
> must be equal to  
> ‘(int)imagePoints2.total()’ is 50

My guess is that the corners on the checkerboard are not recognized for a particular camera and consequently there are fewer object points/image points available for that camera. My code is identical with this one[https://stackoverflow.com/questions/28222763/stereo-calibration-opencv-python-and-disparity-map](https://stackoverflow.com/questions/28222763/stereo-calibration-opencv-python-and-disparity-map).

My assumption was strengthened when I printed out the number of object points/image points for each camera:

> Left\_Image\_Objectpoints: 27  
> Left\_Image\_Imagepoints: 27  
> Right\_Image\_Objectpoints: 50  
> Roght\_Image\_IMagepoints: 50

Can anyone give me a tip on how to make sure I get the same number of object/image points for both images? Or does anyone know this problem in general and knows a solution? I would be very grateful.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [April 21, 2021, 4:38pm UTC](https://forum.opencv.org/t/opencv-steoreocalibration-sometimes-error-sometimes-not/2898/2 "2021-04-21T16:38:33Z")

</div>

isn’t that a limitation of the (terrible) code you copypasted from SO only ?

you indeed have to make sure, it sees a complete chessboard for each image _pair_.  
(if it’s not so, you have to skip _both_ images)  
it’s just a matter of re-organization  
again, you need a loop over image _pairs_, not 2 (shittily copypasted) ones per camera

---

<div class="post-metadata">

**Author:** ![Hans\_HH](https://avatars.discourse-cdn.com/v4/letter/h/ecae2f/32.png) [@Hans\_HH](https://forum.opencv.org/u/Hans_HH)\
**Post date:** [April 21, 2021, 5:01pm UTC](https://forum.opencv.org/t/opencv-steoreocalibration-sometimes-error-sometimes-not/2898/3 "2021-04-21T17:01:14Z")

</div>

Hey, first of all thanks for your answer.

But I wonder why you have such a nasty expression? Not everyone here is a professional and can immediately write the perfect code. So please pay attention to how you write. You may be a professional and can distinguish good and bad code but others cannot.

I see you are a moderator. You should be a role model and not bash other people here.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [April 21, 2021, 5:03pm UTC](https://forum.opencv.org/t/opencv-steoreocalibration-sometimes-error-sometimes-not/2898/4 "2021-04-21T17:03:54Z")

</div>

> [@Hans\_HH](#):
>
> such a nasty expression

apologies for that  
(if you read it twice, you’ll see, that most of the flak goes to the person, who wrote _that SO question_)

apart from that, do you see the problem with the code ?  
if images are skipped in one loop, the image pairs go out of sync

---

<div class="post-metadata">

**Author:** ![Hans\_HH](https://avatars.discourse-cdn.com/v4/letter/h/ecae2f/32.png) [@Hans\_HH](https://forum.opencv.org/u/Hans_HH)\
**Post date:** [April 21, 2021, 5:18pm UTC](https://forum.opencv.org/t/opencv-steoreocalibration-sometimes-error-sometimes-not/2898/5 "2021-04-21T17:18:40Z")

</div>

No problem…and yes I understand the problem. We need always a pair of images. But my problem is how to implement a code which can detected a fault pair to ignore them. I did not find examples in the internet.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [April 21, 2021, 5:21pm UTC](https://forum.opencv.org/t/opencv-steoreocalibration-sometimes-error-sometimes-not/2898/6 "2021-04-21T17:21:18Z")

</div>

the essence of it is:  
you need to do this for both images, and `ret` has to be True for both. only then, you can go on:

```auto

    # Find the chess board corners
    ret, cornersL = cv2.findChessboardCorners(grayL, (9,6),None)
    # If found, add object points, image points (after refining them)
    if ret == True:
         # ok for L
    

```

---

<div class="post-metadata">

**Author:** ![Hans\_HH](https://avatars.discourse-cdn.com/v4/letter/h/ecae2f/32.png) [@Hans\_HH](https://forum.opencv.org/u/Hans_HH)\
**Post date:** [April 21, 2021, 5:25pm UTC](https://forum.opencv.org/t/opencv-steoreocalibration-sometimes-error-sometimes-not/2898/7 "2021-04-21T17:25:08Z")

</div>

Ok Thank you…I will try to implement your advice. I hope it will work, thanks for now.
