Hi there,
i'm new to stereo calibration and tried to get the matrices of a stereo camera and then remap the images, so i could use them for depth-map generation.
I used the sample images `left*.jpg` and `right*.jpg` and parts of this code: http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_calib3d/py_calibration/py_calibration.html#calibration (and also from [samples/python/calibrate.py](https://github.com/Itseez/opencv/blob/master/samples/python/calibrate.py))
So my code is the following:
import cv2
...
img_names = [glob('../data/left*.jpg'), glob('../data/right*.jpg')]
obj_points = [[], []]
img_points = [[], []]
h = ... #
w = ... #
... # get the obj_points and img_points from both image sets like in the examples
# This works fine, i viewed the results with cv2.drawChessboardCorners
rms_l, camera_matrix_l, dist_coeffs_l, _, _ = cv2.calibrateCamera(obj_points[0], img_points[0], (w, h), None, None)
rms_r, camera_matrix_r, dist_coeffs_r, _, _ = cv2.calibrateCamera(obj_points[1], img_points[1], (w, h), None, None)
stereo_flags = 0
stereo_flags |= cv2.CALIB_USE_INTRINSIC_GUESS
stereo_flags |= cv2.CALIB_FIX_INTRINSIC
# run stereo calibration
rms_stereo, camera_matrix_l, dist_coeffs_l, camera_matrix_r, dist_coeffs_r, R, T, E, F = cv2.stereoCalibrate(obj_points[0], img_points[0], img_points[1], camera_matrix_l, dist_coeffs_l, camera_matrix_r, dist_coeffs_r, (w[0], h[0]), flags=stereo_flags)
# run stereo rectification
rectification_matrix_l, rectification_matrix_r, projection_matrix_l, projection_matrix_r, _, _, _ = cv2.stereoRectify(camera_matrix_l, dist_coeffs_l, camera_matrix_r, dist_coeffs_r, (w[0], h[0]), R, T)
map1, map2 = [], []
map1[0], map2[0] = cv2.initUndistortRectifyMap(camera_matrix_l, dist_coeffs_l, rectification_matrix_l, projection_matrix_l, (w[0], h[0]), cv2.CV_16SC2)
map1[1], map2[1] = cv2.initUndistortRectifyMap(camera_matrix_r, dist_coeffs_r, rectification_matrix_r, projection_matrix_r, (w[1], h[1]), cv2.CV_16SC2)
for in in range(2):
img = cv2.imread(img_names[i][0], 0)
imgt = cv2.remap(img, map1[i], map2[i], cv2.INTER_LINEAR)
cv2.imshow('image', imgt)
cv2.waitKey(0)
But then, my the resulting images are very strange (left and right):


Now is my question, what can be my mistake? Did i calculated the matrices not correct or inserted wrong parameters? I saw many examples which are using those functions in a similar way, but altough their results are not like mine.
↧