Ask Your Question

takmin's profile - activity

2018-07-11 10:06:06 -0600 received badge  Famous Question (source)
2017-02-01 12:46:08 -0600 received badge  Notable Question (source)
2016-08-26 07:00:05 -0600 received badge  Teacher (source)
2016-08-09 15:28:54 -0600 received badge  Popular Question (source)
2015-09-08 05:50:04 -0600 received badge  Necromancer (source)
2015-09-08 05:50:04 -0600 received badge  Self-Learner (source)
2015-08-17 05:50:08 -0600 answered a question fisheye::undistortImage() doesn't work. What wrong with my code.

I solved this problem.

That was because fisheye camera parameter was wrong.

I computed fisheye camera parameters by the following code:

rms_err = fisheye::calibrate(object_points, image_points, img_size, camera_matrix, distortion,
            cv::noArray(), cv::noArray(),  fisheye::CALIB_CHECK_COND | fisheye::CALIB_FIX_SKEW);

I solved the problem by changing the code:

rms_err = fisheye::calibrate(object_points, image_points, img_size, camera_matrix, distortion,
cv::noArray(), cv::noArray(), fisheye::CALIB_RECOMPUTE_EXTRINSIC | fisheye::CALIB_CHECK_COND | fisheye::CALIB_FIX_SKEW);
2015-07-01 08:18:20 -0600 received badge  Student (source)
2015-06-22 22:36:16 -0600 asked a question 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?