# Projection matrix

**URL:** <https://forum.opencv.org/t/projection-matrix/5147>\
**Category:** Python\
**Tags:** calib3d\
**Created:** [September 11, 2021, 6:05pm UTC](https://forum.opencv.org/t/projection-matrix/5147 "2021-09-11T18:05:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janck](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/janck/32/1507_2.png) [@Janck](https://forum.opencv.org/u/Janck)\
**Post date:** [September 11, 2021, 6:05pm UTC](https://forum.opencv.org/t/projection-matrix/5147/1 "2021-09-11T18:05:14Z")

</div>

Hello I have one question.

I am using drone and I have his location (x,y,z and rotation) so use this function to calculate projection matrix.

```auto
def projection_matrix(x, y, z, theta, K):

R_x = np.array([[1, 0, 0],
                [0, np.cos(theta[0]), -np.sin(theta[0])],
                [0, np.sin(theta[0]), np.cos(theta[0])]
                ])

R_y = np.array([[np.cos(theta[1]), 0, np.sin(theta[1])],
                [0, 1, 0],
                [-np.sin(theta[1]), 0, np.cos(theta[1])]
                ])

R_z = np.array([[np.cos(theta[2]), -np.sin(theta[2]), 0],
                [np.sin(theta[2]), np.cos(theta[2]), 0],
                [0, 0, 1]
                ])

R = np.dot(R_z, np.dot(R_y, R_x))
t = np.array([x, y, z])

C = np.dot(-np.matrix.transpose(R),t)
R_C = np.matrix.transpose(R)

Rt = np.zeros((3, 4))
Rt[:3, :3] = R_C
Rt[:3, 3] = C

P = np.dot(K, Rt)

return P

P1 = projection_matrix(x=x, y=z, z=y, theta=[0, -theta, 0], K=K)
P0 = projection_matrix(x=0, y=0, z=0, theta=[0, 0, 0], K=K)

```

I used transpose matrix beacuse I was told that camera pose is difrent then world coordinate system. And I used this equations to transform them:  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/4/46d581e0add086ecef063c7b840e7662651a7db7.png)

I don’t know if I am doing this correct beacuse I get off results when I triangulate 2D points with this 2 projection matrix

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [September 11, 2021, 8:22pm UTC](https://forum.opencv.org/t/projection-matrix/5147/2 "2021-09-11T20:22:20Z")

</div>

related:

> <https://stackoverflow.com/questions/69145317/projection-matrix-and-triangulate-points>

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [September 11, 2021, 8:23pm UTC](https://forum.opencv.org/t/projection-matrix/5147/3 "2021-09-11T20:23:20Z")

</div>

as for pose matrices, _you should browse_ this forum. many people have written a lot about this.

this tag contains those discussions:

[https://forum.opencv.org/tag/calib3d](https://forum.opencv.org/tag/calib3d)
