OpenCV-Python - How to format numpy arrays when using calibration functions OpenCV-Python - How to format numpy arrays when using calibration functions numpy numpy

OpenCV-Python - How to format numpy arrays when using calibration functions


In the sample of OpenCV (Camera Calibration) they set the objp to objp2 = np.zeros((8*9,3), np.float32)

However, in omnidirectional camera or fisheye camera, it should be:objp = np.zeros((1,8*9,3), np.float32)

Idea is from here Calibrate fisheye lens using OpenCV — part 1


The correct layout of objpoints is a list of numpy arrays with len(objpoints) = "number of pictures" and each entry beeing a numpy array.

Please have a look at the official help. OpenCV documentation talks about "vectors", which is equivalent of a list or numpy.array. In this instance a "vector of vectors" can be interpreted as a list of numpy.arrays.


The data type is correct, but the shape is not. The expected shape of objpoints supposed to be (n_observations, 1, n_corners_per_observation, 3). Therefore, the code in your case should be:

imgpoints = np.array(imgpoints, dtype=np.float32).reshape(  -1,   1,   pattern_width * pattern_height,   3)

or more general:

imgpoints = np.array(imgpoints, dtype=np.float32).reshape(  n_observations,   1,   n_corners_per_observation,   3)

The error message is slightly misleading.