# What is solvePnP() exactly for? (while i already have the projection matrices P)

I already know that solvePnP() finds the position (rotation and translation) of the camera using the 2d point coordinates and corresponding 3d point coordinates, but i don't really understand why i have to use it after i triangulated some 3d points with 2 cameras and their corresponding 2d points.

Because while triangulating a new 3D point, i already have (need) the projection matrices P1 and P2 of the two cameras (which contains of the R1, R2 and t1, t2 rotation and translations and is already the location of the cameras w.r.t. the new triangulating 3D point).

*My workflow is:*

- Get 2D-correspondences from 2 images.
- Get Essential Matrix E using these 2D-correspondences.
- Get relative orientation (R, t) of the 2 images from the Essential Matrix E.
Set Projection Matrix P1 of camera1 to

`P1 = (1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0);`

and set Projection Matrix P2 of camera2 to

`P2 = (R.at<double>(0, 0), R.at<double>(0, 1), R.at<double>(0, 2), t.at<double>(0), R.at<double>(1, 0), R.at<double>(1, 1), R.at<double>(1, 2), t.at<double>(1), R.at<double>(2, 0), R.at<double>(2, 1), R.at<double>(2, 2), t.at<double>(2));`

Solve least squares problem

`P1 * X = x1 P2 * X = x2`

(solving for X = 3D Point). and so on.....

After that i get a triangulated 3D Point X from these Projection Matrices P1 and P2 and the x1 and x2 2D Point correspondences.

*My question is now again:
Why i need to use now solvePnP() to get the camera location?
Because I already have P1 and P2 which should be already the locations of the cameras (w.r.t. the triangulated 3D points).*