fisheye::undistortImage() doesn't work. What wrong with my code.
First, I computed camera parameters with fisheye::calibration() and saved it as "fisheye0.txt".
%YAML:1.0
IntParam:
camera_matrix: !!opencv-matrix
rows: 3
cols: 3
dt: d
data: [ 4.5573419244698465e+002, 0., 7.9970141134416019e+002, 0.,
4.5329184346860586e+002, 5.9806119342862326e+002, 0., 0., 1. ]
distortion: !!opencv-matrix
rows: 4
cols: 1
dt: d
data: [ -6.5992454656838007e-004, -9.8884504633100923e-001,
4.0189095183182335e+000, -2.4857042509933436e+000 ]
Then, I try to undistort an image with following code:
//// Read Camera Parameters //////
cv::Mat camera_matrix, distortion;
cv::FileStorage fs("fisheye0.txt", cv::FileStorage::READ);
cv::FileNode fn = fs["IntParam"];
fn["camera_matrix"] >> camera_matrix;
fn["distortion"] >> distortion;
// load image
cv::Mat distort_img = cv::imread("distort.jpg");
// undistortion
cv::Mat undistort_img;
cv::fisheye::undistortImage(distort_img, undistort_img, camera_matrix, distortion, camera_matrix);
// save image
cv::imwrite("undistort.jpg", undistort_img);
The result was very strange.
This is input image "distort.jpg" distort.jpg
And this is the output image "undistort.jpg" undistort.jpg
A distort image couldn't be undistorted. What's wrong with my code?