I'm working on a gaze correction project, with a stereo camera setup. For my designed algorithm I need to have the cameras calibrated and the images rectified. I also want to do this in real time. There is an error I get whilst trying to use cv2.stereoCalibrate method, I've searched extensively and have read the official documentation, but none of it managed to help me, even after reworking my code a few times.
Here it is:
import cv2
import numpy as np
import Camera
def calibrate(camera1, camera2):
if(isinstance(camera1, Camera.Camera) & isinstance(camera2, Camera.Camera)):
pass
else:
raise ValueError( "Wrong input types. Expecting: <Camera>, <Camera> \n Got: <" +
str(camera1.__class__) +'>, <' + str(camera2.__class__) +'>.\n')
#instantiate Real-world object point matrix
objPoints = np.zeros(((9*6), 3), np.int32)
objPoints[:,:2] = np.mgrid[0:9,0:6].T.reshape(-1,2)
#Chessboard pattern dimesntions
dims = (9, 6)
#2 arrays to store 3D and 2D object points
objPArray = []
imgPArrayr = []
imgPArrayl = []
#some useful matrices
R = [] # rotation matrix
T = [] # translation vector beterwwn coordinate systems
E = [] # essential matrix
F = [] #fundamental matrix
Q = [] #disparity to depth mapping matrix
criteria = (cv2.TERM_CRITERIA_MAX_ITER + cv2.TERM_CRITERIA_EPS,
100, 1e-5)
flags = (cv2.CALIB_FIX_ASPECT_RATIO + cv2.CALIB_ZERO_TANGENT_DIST +
cv2.CALIB_SAME_FOCAL_LENGTH + cv2.CALIB_FIX_INTRINSIC)
ret,imgr = camera1.read()
ret,imgl = camera2.read()
#Converting to greyscale, as OpenCV requires it for calibration
grey_imgr = cv2.cvtColor(imgr, cv2.COLOR_BGRA2GRAY)
grey_imgl = cv2.cvtColor(imgl, cv2.COLOR_BGRA2GRAY)
ret, cornersr =cv2.findChessboardCorners(grey_imgr,dims)
cv2.drawChessboardCorners(grey_imgr, dims,cornersr,0)
ret, cornersl =cv2.findChessboardCorners(grey_imgl,dims)
cv2.drawChessboardCorners(grey_imgl, dims, cornersl,0)
cv2.imshow("chessboard", grey_imgr)
cv2.imshow("chessboard1", grey_imgl)
imgPArrayl.append(cornersl)
imgPArrayr.append(cornersr)
objPArray.append(objPoints)
'''
cv2.imwrite("./test_images/img_r"+str(i)+".jpg",imgr)
cv2.imwrite("./test_images/img_l"+str(i)+".jpg",imgl)
i+=1
'''
objPArray = [np.asarray(x) for x in objPArray]
imgPArrayl = [np.asarray(x) for x in imgPArrayl]
imgPArrayr = [np.asarray(x) for x in imgPArrayr]
print imgPArrayl
print imgPArrayr
retvalCalib, cameraMatrixl, distCoeffsl, cameraMatrixr, distCoeffsr, R, T, E, F =\
cv2.stereoCalibrate(objPArray,
imgPArrayl,
imgPArrayr,
(9*6),
None,
None,
None,
None,
(640,480),
criteria,
flags)
return retvalCalib, cameraMatrixl, distCoeffsl, cameraMatrixr, distCoeffsr, R, T, E, F
The Error I get is: TypeError: imagePoints1 data type = 17 is not supported
What do I do?
Recompiling OpenCV3 from source and reinstalling it removes this problem.