cv2.stereoCalibrate: objectPoints-error (-210:Unsupported format or combination of formats)
Hey guys! I'm trying to get a disparity images from a stereo camera but I'm getting this error message in cv2.stereoCalibrate:
error: OpenCV(3.4.2) /opt/concourse/worker/volumes/live/9523d527-1b9e-48e0-7ed0-a36adde286f0/volume/opencv-suite_1535558719691/work/modules/calib3d/src/calibration.cpp:3139: error: (-210:Unsupported format or combination of formats) objectPoints should contain vector of vectors of points of type Point3f in function 'collectCalibrationData'
[EDIT] Regarding this error i've seen this answer: https://stackoverflow.com/questions/4... but it didn't solve my problem, because object_points and image_points are in the correct manner.
Image_points: [[2433.414 819.80554] [2436.264 1117.3773 ] ... [ 956.29877 2928.8433 ] [ 955.77747 3234.6638 ]]
Object_points: [[ 0. 0. 0. ] [ 3.6 0. 0. ] ... [25.199999 18. 0. ] [28.8 18. 0. ]]
This is the code i've got so far, but i must admit its mostly from this example: https://stackoverflow.com/questions/2...
I changed a few things to make it compatible with openCV 3.4.2.
import cv2
import numpy as np
import matplotlib.pyplot as plt
calib_l = cv2.imread("Bilder/Calib1.jpg", cv2.IMREAD_GRAYSCALE)
calib_r = cv2.imread("Bilder/Calib2.jpg", cv2.IMREAD_GRAYSCALE)
imgL = cv2.imread("Bilder/Stereo1.jpg", cv2.IMREAD_GRAYSCALE)
imgR = cv2.imread("Bilder/Stereo2.jpg", cv2.IMREAD_GRAYSCALE)
image_size = calib_l.shape[:2]
pattern_size = 9, 6
object_points = np.zeros((np.prod(pattern_size), 3), np.float32)
object_points[:, :2] = np.indices(pattern_size).T.reshape(-1, 2)
object_points *= 3.6
image_points = {}
#chessboard
ret, corners_l = cv2.findChessboardCorners(calib_l, pattern_size, True)
cv2.cornerSubPix(calib_l, corners_l,
(11, 11), (-1, -1),
(cv2.TERM_CRITERIA_MAX_ITER + cv2.TERM_CRITERIA_EPS,
30, 0.01))
corners_l = np.float32(corners_l)
image_points["left"] = corners_l.reshape(-1, 2)
ret, corners_r = cv2.findChessboardCorners(calib_r, pattern_size, True)
cv2.cornerSubPix(calib_r, corners_r,
(11, 11), (-1, -1),
(cv2.TERM_CRITERIA_MAX_ITER + cv2.TERM_CRITERIA_EPS,
30, 0.01))
corners_r = np.float32(corners_r)
image_points["right"] = corners_r.reshape(-1, 2)
#calibrate
(rect_trans, proj_mats, valid_boxes,
undistortion_maps, rectification_maps) = {}, {}, {}, {}, {}
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)
cam_mats = {"left": None, "right": None}
dist_coefs = {"left": None, "right": None}
rot_mat = None
trans_vec = None
e_mat = None
f_mat = None
(ret, cam_mats["left"], dist_coefs["left"], cam_mats["right"],
dist_coefs["right"], rot_mat, trans_vec, e_mat,
f_mat) = cv2.stereoCalibrate(object_points,
image_points["left"], image_points["right"],
image_size, cam_mats["left"],dist_coefs["left"],cam_mats["right"], dist_coefs["right"],rot_mat,
trans_vec, e_mat, f_mat, criteria=criteria, flags=flags)
(rect_trans["left"], rect_trans["right"],
proj_mats["left"], proj_mats["right"],
disp_to_depth_mat, valid_boxes["left"],
valid_boxes["right"]) = cv2.stereoRectify(cam_mats["left"],
dist_coefs["left"],
cam_mats["right"],
dist_coefs["right"],
image_size,
rot_mat, trans_vec, flags=0)
for side in ("left", "right"):
(undistortion_maps[side], rectification_maps[side]) = cv2.initUndistortRectifyMap(cam_mats[side],
dist_coefs[side],
rect_trans[side],
proj_mats[side],
image_size,
cv2.CV_32FC1)
# disparity map
rectified_l = cv2.remap(imgL, undistortion_maps["left"],
rectification_maps["left"],
cv2.INTER_NEAREST)
rectified_r = cv2.remap(imgR, undistortion_maps["right"],
rectification_maps["right"],
cv2.INTER_NEAREST)
cv2.imshow("left", rectified_l)
cv2.imshow("right", rectified_r)
stereo = cv2.StereoBM(cv2.STEREO_BM_BASIC_PRESET, 0, 5)
disparity = stereo.compute(rectified_l, rectified_r, disptype=cv2.CV_32F)
plt.subplot(121).imshow(imgL)
plt.subplot(122).imshow(disparity)
plt.show()
Whats the problem here?
Thanks a lot in advance!!