title: Augmented Reality iOS application tracking issue
body: <p>I am able to detect markers, identify markers and initialise OpenGL objects on screen. The issue I'm having is overlaying them on top of the markers position in the camera world. My camera is calibrated best I can using this method <a href="https://stackoverflow.com/questions/34963337/iphone-6-camera-calibration-for-opencv">Iphone 6 camera calibration for OpenCV</a>. I feel there is an issue with my cameras projection matrix, I create it as follows:</p>
  
  <pre><code>-(void)buildProjectionMatrix:
       (Matrix33)cameraMatrix: 
       (int)screen_width:  
       (int)screen_height: 
       (Matrix44&amp;) projectionMatrix
   {
   float near = 0.01;  // Near clipping distance
   float far  = 100;  // Far clipping distance
  
  // Camera parameters
  float f_x = cameraMatrix.data[0]; // Focal length in x axis
  float f_y = cameraMatrix.data[4]; // Focal length in y axis 
  float c_x = cameraMatrix.data[2]; // Camera primary point x
  float c_y = cameraMatrix.data[5]; // Camera primary point y
  
  std::cout&lt;&lt;"fx "&lt;&lt;f_x&lt;&lt;" fy "&lt;&lt;f_y&lt;&lt;" cx "&lt;&lt;c_x&lt;&lt;" cy "&lt;&lt;c_y&lt;&lt;std::endl;
  std::cout&lt;&lt;"width "&lt;&lt;screen_width&lt;&lt;" height "&lt;&lt;screen_height&lt;&lt;std::endl;
  
  projectionMatrix.data[0] = - 2.0 * f_x / screen_width;
  projectionMatrix.data[1] = 0.0;
  projectionMatrix.data[2] = 0.0;
  projectionMatrix.data[3] = 0.0;
  
  projectionMatrix.data[4] = 0.0;
  projectionMatrix.data[5] = 2.0 * f_y / screen_height;
  projectionMatrix.data[6] = 0.0;
  projectionMatrix.data[7] = 0.0;
  
  projectionMatrix.data[8] = 2.0 * c_x / screen_width - 1.0;
  projectionMatrix.data[9] = 2.0 * c_y / screen_height - 1.0;
  projectionMatrix.data[10] = -( far+near ) / ( far - near );
  projectionMatrix.data[11] = -1.0;
  
  projectionMatrix.data[12] = 0.0;
  projectionMatrix.data[13] = 0.0;
  projectionMatrix.data[14] = -2.0 * far * near / ( far - near );
  projectionMatrix.data[15] = 0.0;
  }
  </code></pre>
  
  <p>This is the method to estimate the position of the marker:</p>
  
  <pre><code>void MarkerDetector::estimatePosition(std::vector&lt;Marker&gt;&amp; detectedMarkers)
  {
  for (size_t i=0; i&lt;detectedMarkers.size(); i++)
  {                   
      Marker&amp; m = detectedMarkers[i];
  
      cv::Mat Rvec;
      cv::Mat_&lt;float&gt; Tvec;
      cv::Mat raux,taux;
      cv::solvePnP(m_markerCorners3d, m.points, camMatrix, distCoeff,raux,taux);
      raux.convertTo(Rvec,CV_32F);
      taux.convertTo(Tvec ,CV_32F);
  
      cv::Mat_&lt;float&gt; rotMat(3,3); 
      cv::Rodrigues(Rvec, rotMat);
  
      // Copy to transformation matrix
      for (int col=0; col&lt;3; col++)
      {
          for (int row=0; row&lt;3; row++)
          {        
              m.transformation.r().mat[row][col] = rotMat(row,col); // Copy rotation component
          }
          m.transformation.t().data[col] = Tvec(col); // Copy translation component
      }
  
      // Since solvePnP finds camera location, w.r.t to marker pose, to get marker pose w.r.t to the camera we invert it.
      m.transformation = m.transformation.getInverted();
  }
  }
  </code></pre>
  
  <p>The OpenGL shape is able to track and account for size and roation, but something is going wrong with the translation. If the camera is turned 90 degrees, the opengl shape swings around 90 degrees about the centre of the marker. Its almost as if I am translating before rotating, but I am not. </p>
  
  <p>See video for issue:</p>
  
  <p><a href="https://vid.me/fLvX" rel="nofollow noreferrer">https://vid.me/fLvX</a></p>