title: Inverse Matrix OpenCV. Matrix.inv() not working properly
body: <p>I have one problem for which I could not find any solution.</p>
  
  <p>I have to make some calculations with the inverse of one known matrix.</p>
  
  <pre><code>Matrix homography=
  
  1.1688, 0.23, 62.2,
  
  -0.013,1.225, -6.29,
  
  0, 0, 1, 
  </code></pre>
  
  <p>and then:</p>
  
  <pre><code>Mat homoInv=homography.inv();
  </code></pre>
  
  <p>The content of the matrix would be:</p>
  
  <pre><code>1.81381e-29, 15.1628, -7.57361e+17, 
  
  0, -0, 0, 
  
  5.4561e-33, -2.40123e+34, -1.38198e-05
  </code></pre>
  
  <p>That of course is wrong as I already checked the result in Matlab. Both matrix are displayed and read as floats, and their depth is a <code>64FC1</code>.</p>
  
  <p>Does anyone have any idea of what could be done?</p>
  
  <p>Thanks All</p>
  
  <p>More code:</p>
  
  <pre><code>int main(int argc, char ** argv )
  { 
    Mat homogra(3,3,CV_64FC1);
    Mat coord(3,1,CV_64FC1);
    Mat result(target.size(),CV_8UC1);
    homogra.at&lt;float&gt;(0,0)=1.1688;
    homogra.at&lt;float&gt;(0,1)=0.23;
    homogra.at&lt;float&gt;(0,2)=(-62.20);
    homogra.at&lt;float&gt;(1,0)=(-0.013);
    homogra.at&lt;float&gt;(1,1)=1.225;
    homogra.at&lt;float&gt;(1,2)=-6.29;
    homogra.at&lt;float&gt;(2,0)=0;
    homogra.at&lt;float&gt;(2,1)=0;
    homogra.at&lt;float&gt;(2,2)=1;
    printMatrix(homogra);
  
    Mat inverse=homogra.inv();
    printMatrix(inverse);
  }
  </code></pre>
  
  <p>function printMatrix:</p>
  
  <pre><code>void printMatrix(Mat M){
  cout&lt;&lt;"Tipo de matriz:"&lt;&lt;M.type()&lt;&lt;endl;
   // dont print empty matrices
    if (M.empty()){
      cout &lt;&lt; "---" &lt;&lt; endl;
      return;
    }
    // loop through columns and rows of the matrix
    for(int i=0; i &lt; M.rows; i++){
        for(int j=0; j &lt; M.cols ; j++){
        cout &lt;&lt; M.at&lt;float&gt;(i,j) &lt;&lt; ", "&lt;&lt;endl;
        }
      cout&lt;&lt;"Change\n"&lt;&lt;endl;
  }
    }
  </code></pre>
  
  <p>But the error is not in <code>printMatrix</code>, as If i print the elements separately I obtain the same strange result in the numbers of inverse.</p>