OpenCV SteoreoCalibration sometimes error, sometimes not

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 onehttps://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.

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

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.

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

1 Like

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.

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:


    # 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
    
1 Like

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