I'm having trouble solving the following problem. Hopefully someone can help!
The following is in homogeneous coordinates. I am projecting a point into a pinhole camera. $\lambda$ is an unknown scaling factor, all other variables are known.
$\mathbf{x} = \mathtt{P}(\lambda \mathbf{X} + \mathbf{Q})$
P is a 3x4 projection matrix. I'd like to solve for $\lambda$. Here's some example data:
x = [-0.4052 -0.0502 1.0000]'
P = [1 0 0 0
0 1 0 0
0 0 1 0]
X = [0.3925 0.0465 -0.9313 1.0000]'
Q = [-18.4299, 0, -7.7678, 1.0000]'
And for this data, I know $\lambda$ is about 1430 if I just brute force search. Plugging the numbers and this result into the equation gives a correct solution. However, surely there must be a direct solution for $\lambda$? I can't seem to work it out!
Thanks,
John
I think what you actually want is the following: calling $y = P ( \lambda X + Q)$, you want $\left( \frac{y_1}{y_3}, \frac{y_2}{y_3} \right)$ to be as close to $\left( \frac{x_1}{x_3}, \frac{x_2}{x_3} \right)$ as possible.
If so, then the target function to minimize is $\left| \left( \frac{x_1}{x_3} - \frac{y_1}{y_3} \right)^2 + \left( \frac{x_2}{x_3} - \frac{y_2}{y_3} \right) \right|^2$, which is a function of the form $$ \frac{\alpha \lambda^2 + 2 \beta \lambda + \gamma}{\left( \lambda X_3 + Q_3 \right)^2} $$ with $\alpha = (x_3 X_1 - x_1 X_3)^2 + (x_3 X_2 - x_2 X_3)^2$, $\beta = (x_3 X_1 - x_1 X_3) (x_3 Q_1 - x_1 Q_3) + (x_3 X_2 - x_2 X_3) (x_3 Q_2 - x_2 Q_3)$, and $\gamma = (x_3 Q_1 - x_1 Q_3)^2 + (x_3 Q_2 - x_2 Q_3)^2$.
This system has a simple minimum at $$ \lambda = \frac{\beta Q_3 - \gamma X_3}{\beta X_3 - \alpha Q_3}, $$ which in your case turns out to be close to 1426.3