title: Using OpenCVs findTransformECC to find the affine transformation applied with OpenCVs warpAffine does not give the same warp matrix back like used
body: <p>I am currently trying to do a kind of selftest of the OpenCVs implementation of the function findtranfromECC (<a href="http://docs.opencv.org/3.0-beta/modules/video/doc/motion_analysis_and_object_tracking.html#findtransformecc" rel="nofollow">http://docs.opencv.org/3.0-beta/modules/video/doc/motion_analysis_and_object_tracking.html#findtransformecc</a> ).</p>
  
  <p>To do so I create a warp-matrix by myself and do the affine transformation with the function warpAffine given by OpenCV.
  After the affine Transform I use the input of the affine Transform and the warped output in the TransfromECC function. I hoped I would get back the same matrix like I used in the affine transform, bud sadly it differs a lot - it is a completly different one. </p>
  
  <p>In the code example I put at the end of the post I got the following matrix for making the affine Transform:</p>
  
  <p>[0.850332161003909, 0.1778601204261232, 0]<br>
  [-0.06752637272097255, 0.3701713812908899, 712.799877929688]</p>
  
  <p>But the calculated Matrix by findTransformECC is:</p>
  
  <p>[1.0151283, -0.0033983635, -5.6531301]<br>
  [-0.023056569, 1.038756, -8.7541409]</p>
  
  <p>I also compared the eigen-Values:</p>
  
  <p>For doing the affine Transform:</p>
  
  <p>[127021.1755113913]<br>
  [0]  </p>
  
  <p>Calulated Warp-Matrix eigenvalues:</p>
  
  <p>[2.945044]<br>
  [0]</p>
  
  <p>Does anyone has made the same experience or might now what causes this error?</p>
  
  <p>I appreciate everyones help </p>
  
  <pre><code>Point2f srcTri[3];
  Point2f dstTri[3];
  float scale = (float)1 / (float)255;
  
  //Matri for first affine transform
  Mat warp_mat(2, 3, CV_32FC1); 
  //Matrix for back affine transform
  Mat warp_mat2 = Mat::eye(2, 3, CV_32FC1);
  
  
  Mat src, warp_dst, warp_rotate_dst;
  
  
  //Get Image from Image class and convert it to 8 bit which is used by 
  //findtransfromsEcc
  this-&gt;DemosaicedDestination.convertTo(src, CV_8UC1, scale, 0);
  
  
  //container for warp destination
  warp_dst = Mat::zeros(src.rows, src.cols, CV_8UC1);
  
  
  //Points for warp matrix
  srcTri[0] = Point2f(0, 0);
  srcTri[1] = Point2f(src.cols - 1, 0);
  srcTri[2] = Point2f(0, src.rows - 1);
  
  dstTri[0] = Point2f(src.cols*0.0, src.rows*0.33);
  dstTri[1] = Point2f(src.cols*0.85, src.rows*0.25);
  dstTri[2] = Point2f(src.cols*0.15, src.rows*0.7);
  
  
  //get the affine transformation warp mat
  warp_mat = getAffineTransform(srcTri, dstTri);
  //Do the affine transformation
  warpAffine(src, warp_dst, warp_mat, warp_dst.size());
  
  //show affine transformation
  imshow("src", src);
  waitKey(0);
  
  cout &lt;&lt; "warp matrix used: " &lt;&lt; warp_mat &lt;&lt; endl;
  namedWindow("warped to ", WINDOW_NORMAL);
  imshow("warped to",warp_dst);
  
  TermCriteria criteria(TermCriteria::COUNT + TermCriteria::EPS, 2500, 1e-1);
  try{
      this-&gt;cc = findTransformECC(warp_dst, src, warp_mat2, MOTION_AFFINE, criteria);
  }
  catch (Exception&amp; e){
      const char* err_msg = e.what();
      cout &lt;&lt; err_msg;
      return false;
  }
  
  
  //Do the affine transformation back
  warpAffine(warp_dst, src, warp_mat2, src.size());
  
  
  //show backwarded afine transform
  namedWindow("back warped transform", WINDOW_NORMAL);
  imshow("back warped transform", src);
  waitKey(0);
  
  
  //show calculated matrix, should be the same was warp matrix used 
  cout &lt;&lt; "calculated warp matrix 1 " &lt;&lt; warp_mat2 &lt;&lt; endl;
  </code></pre>