I am trying to use openCV for camera calibration. I do not have a problem as long as I use the cv2.findChessBoardCorners to find my calibration targets in the image, but if I use my own function to find the points and build an array with the points, I get an error when trying to estimate the camera parameters. Here is an example that will throw the same error.
import numpy as np
import cv2
pattern_size = (4, 3)
pattern_points = np.zeros( (np.prod(pattern_size), 3), np.float32 )
pattern_points[:,:2] = np.indices(pattern_size).T.reshape(-1, 2)
pattern_points *= 20
obj_points = []
img_points = []
for fn in range(5):
corners = np.asarray(pattern_points[:,1:], dtype=np.float32)
img_points.append(corners.reshape(-1, 2))
obj_points.append(pattern_points)
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(obj_points,
img_points,
(1088, 2048),
None,
None)
If I instead make the corners array with the usual
ret, corners = cv2.findChessboardCorners(gray, (4,3))
it works fine. The type of corners is an ndarray size (12,2) in both cases and the elements are float32.
Why do I get this error:
OpenCV Error: Unsupported format or combination of formats (imagePoints1 should contain vector of vectors of points of type Point2f) in cv::collectCalibrationData, file C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\calib3d\src\calibration.cpp, line 2982
when I try to construct the img_points array from scratch instead of using cv2.findChessboardCorners?
imPts.astype('float32')
,obPts.astype('float32')
when using them inside the function. If more than one frame is used, then do that for each frame. Hope that does the trick – trox