# GPS-Induced Disparity Correction for Accurate Object Placement in Augmented Reality
## 2 Materials and Methods
### Localization of 3D Objects
A rigid body transformation in 3D space comprises both rotation, which can be derived using (4) to obtain \(R\), a \(3\times 3\) matrix representing the rotation, and translation, represented by vector \(T=(t\_x,t\_y,t\_z)\). This matrix formulates the following transformation:  
\[\left[ \begin{array}{cc}R&1\\ 0&1\end{array} \right]\left[ \begin{array}{cc}I&T\\ 0&1\end{array} \right]=\left[ \begin{array}{cc}R&RT\\ 0&1\end{array} \right] \tag{5}\]  
To transform a point \(P=(x,y,z)\) using this transformation, with and without GPS error, the following steps were taken:  
In the case where GPS errors are incorporated, the position of an object projected into the camera space is represented as:  
\[P^{\prime}_{e}=\left[ \begin{array}{cc}R&RT_{e}\\ 0&1\end{array} \right].P \tag{6}\]  
Conversely, in the absence of GPS errors, the position of an object projected onto the camera space is represented as:  
\[P^{\prime}=\left[ \begin{array}{cc}R&RT\\ 0&1,\end{array} \right].P \tag{7}\]  
where \(P\) denotes the position of the object in the world coordinate system, and \(T_{e}\) and \(T\) represent the translation vectors with and without errors, respectively. The results are in homogeneous coordinates and must be converted back to Cartesian coordinates for practical applications. The intrinsic parameters of a camera, including the focal lengths \(f_{x}\) and \(f_{y}\), principal points \(c_{x}\) and \(c_{y}\), and skew coefficient, define its internal characteristics. The intrinsic matrix \(K\) that encapsulates these parameters is as follows:  
\[K=\left[ \begin{array}{ccc}f_{x}&0&c_{x}\\ 0&f_{y}&c_{y}\\ 0&0&1\end{array} \right] \tag{8}\]  
The transformation of a world coordinate point \(P_{\text{world}}=(x,y,z)\) into the camera coordinate system involves the use of the extrinsic parameters of the camera (rotation \(R\) and translation \(T\)). This transformed point \((X^{\prime},Y^{\prime},Z^{\prime})^{\prime}\) is then projected onto the image plane \((u,v,w)^{\prime}\) using the following intrinsic matrix:  
\[\left( \begin{array}{c}u\\ v\\ w\end{array} \right)=K\cdot\left( \begin{array}{c}X^{\prime}\\ Y^{\prime}\\ Z^{\prime}\end{array} \right) \tag{9}\]  
In the final step, these homogeneous coordinates are converted into pixel coordinates in the image sensor as follows:  
\[x_{\text{pixel}}=\frac{u}{w},\quad y_{\text{pixel}}=\frac{v}{w} \tag{10}\]  
Using the differences in the image plane coordinates \(P^{\prime}\) and \(P^{\prime}_{e}\), we aim to determine the difference \(T_{\text{delta}}\) in the GPS coordinates to pinpoint the camera's exact location. For erroneous pixel coordinates:  
\[P^{\prime}_{e}=Z\cdot K^{-1}\cdot \begin{pmatrix}x_{\text{pixel}\_\text{error} }\\ y_{\text{pixel}\_\text{error}}\\ 1\end{pmatrix}  \tag{11}\]  
For reference pixel coordinates:  
\[P^{\prime}=Z\cdot K^{-1}\cdot \begin{pmatrix}x_{\text{pixel}}\\ y_{\text{pixel}}\\ 1\end{pmatrix}  \tag{12}\]  
We transform these points into world coordinates using the rotation matrix R. Upon applying the inverse rotation matrix to the world coordinates, we obtain  
\[Z=R^{-1}P \tag{13}\]  
where \(Z\) represents the point depth in the coordinate system of the camera. This depth is critical for accurately projecting a point onto a 2D image plane by leveraging the camera's intrinsic matrix \(K\). The intrinsic matrix then scales this depth along the X- and Y-coordinates to compute the final image coordinates, ensuring an accurate representation of the 3D world point on the 2D image. \(P^{\prime}_{he}\) and \(P^{\prime}\) represent the transformation in the extended and basic environments, respectively.