title: Assertion failed (K.size() == Size(3, 3) && (D.empty() || D.total() == 4)) in initUndistortRectifyMap
body: <p>I have an OpenCV-3.3.1 code that receives fisheye images and the camera_info.</p>
  <p>I'm using the <code>cv::fisheye::undistortImage(input_img, output_img, K, D);</code> function to undistort my fisheye images. My camera matrix is a 3 by 3 vector of type double, whereas my distortion coefficients vector is a 1 by 5 vector of type double.</p>
  <p>When I print out my <code>K</code> and <code>D</code> variables I get:</p>
  <pre><code>D = 
  -0.0107835 0.0484281 -0.045424 0.00873738 0 
  
  K = 
  286.704 0   413.346 
  0   286.782 397.179 
  0   0   1   
  </code></pre>
  <p>However the <code>cv::fisheye::undistortImage</code> throws the following error:</p>
  <blockquote>
  <p>[ERROR] [1599838848.368370935]: cv exception:
  /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/calib3d/src/fisheye.cpp:427:
  error: (-215) K.size() == Size(3, 3) &amp;&amp; (D.empty() || D.total() == 4)
  in function initUndistortRectifyMap</p>
  </blockquote>
  <p>I went into the <a href="https://github.com/opencv/opencv/blob/a871f9e4f7d83dc5851f965bdba5cd01bb7527fe/modules/calib3d/src/fisheye.cpp#L427" rel="nofollow noreferrer">source code</a> and found out that the condition for this error is:</p>
  <p><code>CV_Assert(K.size() == Size(3, 3) &amp;&amp; (D.empty() || D.total() == 4));</code></p>
  <p>Then I printed out the following: (Note that <code>‘class std::vector&lt;double&gt;’ has no member named ‘total’</code>, this is a specific member for <a href="https://docs.opencv.org/3.4/dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba" rel="nofollow noreferrer">InputArray</a> so I printed out the size of vector <code>D</code>.)</p>
  <pre><code>K.size() = 3
  D.empty() = 0
  D.size() = 5
  </code></pre>
  <p>Based on this the <code>K.size() == Size(3, 3) &amp;&amp; (D.empty() || D.total() == 4)</code> should be returning a False and the Assertion Error shouldn't be thrown. <em>What am I missing here?</em></p>
  <p>From Documentation:</p>
  <p><code>cv::fisheye::undistortImage(InputArray distorted, OutputArray undistorted, InputArray K, InputArray D, InputArray Knew=cv::noArray(), const Size &amp;new_size=Size())</code></p>
  <p>P.s. I saw <a href="https://stackoverflow.com/questions/56536111/215assertion-failed-with-initundistortrectifymap">this question</a> but it doesn't address my question.</p>