Imagine a table with a $XY$ coordinate system in its plane and a green vertical line at $X=XL$. Further imagine there is a camera placed in $(XC,YC,ZC)$ looking down on the table:
The position of the camera is just approximately known: $XC \approx XL$.
Also the camera will be $4$ degrees rotated around the $x$-axis.
On top of that the camera will be very slightly rotated with an unknown rotation that should be estimated.
Now imagine the following photo of the green line taken by the camera:
It appears that the camera is rotated an angle $\gamma$ around the $z$-axis: $$ \tan(\gamma) = DX/DY $$
However due to the $4$ degrees rotation around the $x$-axis this apparent rotation around the $z$-axis may not be correct?
What is the correct rotation around the $z$-axis?
As mentioned it can be assumed that the rotations around the $z$-axis ($\gamma$) and $y$-axis ($\beta$) are very small.


Assuming that initially the camera is aligned with the world coordinate axes, then we apply $3$ rotations, first about its $x$ axis by $\alpha$, then about its $y$ axis by $\beta$, then about its $z$ axis by $\gamma$, then the rotation matrix of the camera will be
$ R = R_x(\alpha) R_y(\beta) R_z(\gamma) $
And this is equal to,
$R = \begin{bmatrix} c_2 c_3 && - c_2 s_3 && s_2 \\ c_1 s_3 + s_1 s_2 c_3 && c_1 c_3 - s_1 s_2 s_3 && - s_1 c_2 \\ s_1 s_3 + s_1 s_2 c_3 && s_1 c_3 + c_1 s_2 s_3 && c_1 c_2 \end{bmatrix} $
where $c_1 = \cos(\alpha), s_1 = \sin(\alpha) , c_2 = \cos(\beta) , s_2 = \sin(\beta) , c_3 = \cos(\gamma) , s_3 = \sin(\gamma) $
Now, given $P$ on the $xy$ plane, its coordinates as related to coordinates of its image is
$P(\text{world}) = C + t R P(\text{image}) \hspace{10pt} (1)$
Therefore,
$P(\text{image}) = (1/t) R^T (P(\text{world}) - C) $
now we have $P(\text{world}) = (xL , s , 0 )$ where $s \in \mathbb{R}$
For simplicity, we can take $XC = XL$, $YC = 0$ , then
$P(\text{image}) = (1/t) R^T (0 , s , - ZC) $
This gives
$P(\text{image}) = (1/t) ( s (c_1 s_3 + s_1 s_2 c_3) - ZC (s_1 s_3 + s_1 s_2 c_3) , s (c_1 c_3 - s_1 s_2 s_3 ) - ZC (s_1 c_3 + c_1 s_2 s_3 ) , s (- s_1 c_2 ) - ZC (c_1 c_2 ) )$
since we're talking about slope, we note that $P(\text{image})$ is a straight line whose slope is
$m = \text{slope(image)} = \dfrac{(c_1 c_3 - s_1 s_2 s_3) }{ (c_1 s_3 + s_1 s_2 c_3)}$
We know the slope $m$ of the line in the image.
So we now have,
$ m (c_1 s_3 + s_1 s_2 c_3) = c_1 c_3 - s_1 s_2 s_3 $
This gives a relation between $\beta$ and $\gamma$ because $\alpha = 4^\circ$ is known.
Dividing by $c_1 c_3$ , gives
$ m ( \tan(\gamma) + \tan(\alpha) \sin(\beta) ) = 1 - \tan(\alpha) \tan(\gamma) \sin(\beta) $
let $\tan(\alpha) = K $, then
$ m (\tan(\gamma) + K \sin(\beta) ) = 1 - K \tan(\gamma) \sin(\beta) $
From here we can solve for $\tan(\gamma)$
$\tan(\gamma) = \dfrac{(1 - m K \sin(\beta) )}{ ( m + K \sin(\beta) )} $