title: Perform calibration on fisheye image - cancelling fisheye effect
body: <p>I'm currently using opencv library with c++, and my goal is to cancel a fisheye effect on an image ("make it plane") 
  I'm using the function "undistortImage" to cancel the effect but I need before to perform camera calibration in order to find the parameters K, Knew, and D, but I didn't understand exactly the documentation ( link: <a href="http://docs.opencv.org/master/db/d58/group__calib3d__fisheye.html#gga37375a2741e88052ce346884dfc9c6a0a0899eaa2f96d6eed9927c4b4f4464e05" rel="nofollow">http://docs.opencv.org/master/db/d58/group__calib3d__fisheye.html#gga37375a2741e88052ce346884dfc9c6a0a0899eaa2f96d6eed9927c4b4f4464e05</a>). 
  From my understanding, I should give two lists of points and the function "calibrate" is supposed to return the arrays I need. So my question is the following: given a fisheye image, how am I supposed to pick the two lists of points to get the result ? This is for the moment my code, very basic, just takes the picture, display it, performs the undistortion and displays the new image. The elements in the matrix are random, so currently the result is not as expected. Thanks for the answers.</p>
  
  <pre><code>#include "opencv2\core\core.hpp"
  #include "opencv2\highgui\highgui.hpp"
  #include "opencv2\calib3d\calib3d.hpp"
  #include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  
  
  using namespace std;
  using namespace cv;
  
  int main(){
  
      cout &lt;&lt; " Usage: display_image ImageToLoadAndDisplay" &lt;&lt; endl;
      Mat image;
      image = imread("C:/Users/Administrator/Downloads/eiffel.jpg", CV_LOAD_IMAGE_COLOR);   // Read the file
      if (!image.data)                              // Check for invalid input
      {
          cout &lt;&lt; "Could not open or find the image" &lt;&lt; endl;
          return -1;
      }
      cout &lt;&lt; "Input image depth: " &lt;&lt; image.depth() &lt;&lt; endl;
  
      namedWindow("Display window", WINDOW_AUTOSIZE);// Create a window for display.
      imshow("Display window", image);                   // Show our image inside it.
  
      Mat Ka = Mat::eye(3, 3, CV_64F); // Creating distortion matrix
      Mat Da = Mat::ones(1, 4, CV_64F);
      Mat dstImage(image.rows, image.cols, CV_32F);
  
      cout &lt;&lt; "K matrix depth: " &lt;&lt; Ka.depth() &lt;&lt; endl;
      cout &lt;&lt; "D matrix depth: " &lt;&lt; Da.depth() &lt;&lt; endl;
  
      Mat Knew = Mat::eye(3, 3, CV_64F);
      std::vector&lt;cv::Vec3d&gt; rvec;
      std::vector&lt;cv::Vec3d&gt; tvec;
      int flag = 0; 
      std::vector&lt;Point3d&gt; objectPoints1 = { Point3d(0,0,0),  Point3d(1,1,0),  Point3d(2,2,0), Point3d(3,3,0), Point3d(4,4,0), Point3d(5,5,0), 
          Point3d(6,6,0),  Point3d(7,7,0),  Point3d(3,0,0), Point3d(4,1,0), Point3d(5,2,0), Point3d(6,3,0), Point3d(7,4,0),  Point3d(8,5,0),  Point3d(5,4,0), Point3d(0,7,0), Point3d(9,7,0), Point3d(9,0,0), Point3d(4,3,0), Point3d(7,2,0)};
      std::vector&lt;Point2d&gt; imagePoints1 = { Point(107,84),  Point(110,90),  Point(116,96), Point(126,107), Point(142,123), Point(168,147),
          Point(202,173),  Point(232,192),  Point(135,69), Point(148,73), Point(165,81), Point(189,93), Point(219,112),  Point(248,133),  Point(166,119), Point(96,183), Point(270,174), Point(226,56), Point(144,102), Point(206,75) };
  
      std::vector&lt;std::vector&lt;cv::Point2d&gt; &gt; imagePoints(1);
      imagePoints[0] = imagePoints1;
      std::vector&lt;std::vector&lt;cv::Point3d&gt; &gt; objectPoints(1);
      objectPoints[0] = objectPoints1;
      fisheye::calibrate(objectPoints, imagePoints, image.size(), Ka, Da, rvec, tvec, flag); // Calibration
      cout &lt;&lt; Ka&lt;&lt; endl;
      cout &lt;&lt; Da &lt;&lt; endl;
      fisheye::undistortImage(image, dstImage, Ka, Da, Knew); // Performing distortion
      namedWindow("Display window 2", WINDOW_AUTOSIZE);// Create a window for display.
      imshow("Display window 2", dstImage);                   // Show our image inside it.
  
      waitKey(0);                                          // Wait for a keystroke in the window
      return 0;
  }
  </code></pre>