pythonopencvstereoscopy

Python OpenCV Stereo Calibrate Object Points


I am really having a hard time to grasp this thing, I'm only a beginner in python, and I cannot find an explanation to this code.

# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((6*9,3), np.float32)
objp[:,:2] = np.mgrid[0:9,0:6].T.reshape(-1,2)

the original is that, 9 is 7. I assumed that 9 and 6 are the inner corners of the columns and rows of the chessboard pattern respectively. (so my chessboard is really 10x7)

Now, I know the size of the square on the chessboard, what i cannot figure out is where to put it there.

As every iteration on every image, the code I found just do this:

objpoints.append(objp)

And I can see, it's always pushing the same object again and again.

Two Questions: how does objpoints.append(objp) on every iteration make a difference?

how can i specify in the code, the square size? where should i put it?

I know that object points are the 3d points of each squares in the chessboard, that's why im very confused it's not even manipulated in each iteration.

Thanks!

EDIT: My code for stereocalib: http://pastebin.com/pw5n3pme

(It is just a modified version of individual camera calibration)


Solution

  • I will assume you are working with this code or a similar one.

    First question

    how does objpoints.append(objp) on every iteration make a difference? It doesn't. From the line you posted, look at this

    objp[:,:2] = np.mgrid[0:9,0:6].T.reshape(-1,2)
    

    Here it is calculating the disposition of the chessboard corners, which, in a certain chessboard, are always the same. Every iteration you find different imgpoints in your camera for the same points in the chessboard.

    If the were not the same points, you could not perform the calibration

    Second question

    how can i specify in the code, the square size? where should i put it?

    in the tutorial I posted, for Python and OpenCV, you should not specify the square size. It is mono-calibration, so square size is related only to scale factor, (quite) useless in mono camera. You will obtain a correct camera matrix with an undefined (or maybe equal to 1) scale factor.

    If you have a different code (e.g stereo calibration), post it and I will try to find where the square dimension has to be put.