I am trying to build a stereo rig and plan on using OpenCVs stereoCalibrateExtended() method in a Python environment. I am using OpenCV 4.9.0 and Python 3.9.13. When setting the flag cv2.CALIB_USE_EXTRINSIC_GUESS, cv2 throws the error:
error: OpenCV(4.9.0) D:aopencv-pythonopencv-pythonopencvmodulescoresrcmatrix_wrap.cpp:1346: error: (-215:Assertion failed) mtype == type0 || (CV_MAT_CN(mtype) == 1 && ((1 << type0) & fixedDepthMask) != 0) in function ‘cv::_OutputArray::create’
The code i am using:
OAKC_cameraMatrix = np.load('Stereocalibrateextended/center_cameraMatrix.npy')
tCSI_cameraMatrix = np.load('Stereocalibrateextended/tCSI_cameraMatrix.npy')
objpoints = np.load('Stereocalibrateextended/objpoints.npy')
imgpoints_OAKC = np.load('Stereocalibrateextended/imgpointsB.npy')
imgpoints_tCSI = np.load('Stereocalibrateextended/imgpointsT.npy')
OAKC_cameraMatrix = np.asarray(OAKC_cameraMatrix, np.float32)
tCSI_cameraMatrix = np.asarray(tCSI_cameraMatrix, np.float32)
objpoints = np.asarray(objpoints, np.float32)
imgpoints_OAKC = np.asarray(imgpoints_OAKC, np.float32)
imgpoints_tCSI = np.asarray(imgpoints_tCSI, np.float32)
dist_OAKC = np.array([0,0,0,0,0], dtype=np.float32)
dist_tCSI = np.array([0,0,0,0,0], dtype=np.float32)
R = np.array([[1,0,0], [0,1,0], [0,0,1]], dtype=np.float32)
T = np.array([[0],[38],[0]], dtype=np.float32)
flags = cv2.CALIB_USE_EXTRINSIC_GUESS
retStereo, cameraMatrix_1, dist_1, cameraMatrix_2, dist_2, rot, trans, essentialMatrix, fundamentalMatrix, rvecs, tvecs, perViewErrors = cv2.stereoCalibrateExtended(objpoints, imgpoints_OAKC, imgpoints_tCSI, OAKC_cameraMatrix, dist_OAKC, tCSI_cameraMatrix, dist_tCSI, (1920,1080), R, T, flags=flags)
Both camera matrices are np.ndarrays of shape 3×3, objpoints is a np.ndarray of shape 30x54x3, both imgpoints are np.ndarrays of shape 30x54x2 and all of the arguments have the dtype float32.
Where does this error come from and how is it fixable?
Without cv2.CALIB_USE_EXTRINSIC_GUESS and when using the normal cv2.stereoCalibrate() function, the error is not raised. The problem is that the found translation vector has a false z offset of about 23mm without an initial rotation and translation estimate.
Lars is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.