# Identification of Location and Camera Parameters for Public Live Streaming Web Cameras
## 4 Formulation of the Problem and Its Solution Algorithm
### Solution Algorithm
#### 4.1.4 Obtain the Mapping \(\Lambda^{-1}\) for \(Q_{im}\)  
Let \(\hat{Q}_{im}=\Theta(Q_{im})\) be the area in \(\hat{\Phi}\) corresponding to \(Q_{im}\) in the image \(\Phi\). \(Q_{emu}\) and \(Q_{c}\) are the domain \(Q\) on the road plane in coordinates \(F_{emu}\), and \(F_{c}\), respectively. From (27), we obtain  
\[Q_{emu}=R^{T}Q_{c}+O,\ Q_{c}=R(Q_{emu}-O). \tag{28}\]  
From Clause 2 of the problem statement, it follows that an image of \(Q_{c}\) is visible in \(\Phi\) (and in \(\hat{\Phi}\), so \(\hat{Q}_{im}\subset\hat{\Phi}\) ).  
We can convert the ENU coordinates of points \(\{P_{emu}^{Q}\}\) to \(F_{c}\) by following (27). We denote the result as \(\{P_{c}^{Q}\}_{i=1}^{L}\). Let \(P_{c}^{Q_{i}}=(x_{c}^{i},y_{c}^{i},z_{c}^{i})\).  
We approximate its plane with the least squares method. The plane is defined in \(F_{c}\) by the equation  
\[p_{x}x_{c}+p_{y}y_{c}+z_{c}=p_{z},\ p=\begin{bmatrix}p_{x}\\ p_{y}\\ p_{z}\end{bmatrix}. \tag{29}\]The matrix \(D\) and vector \(E\) represent the points on the road:  
\[D=\begin{bmatrix}x_{c}^{1}&y_{c}^{1}&-1\\ x_{c}^{2}&y_{c}^{2}&-1\\ \vdots&\vdots&\vdots\\ x_{c}^{L}&y_{c}^{L}&-1\end{bmatrix},\,E=\begin{bmatrix}-z_{c}^{1}\\ -z_{c}^{2}\\ \vdots\\ -z_{c}^{L}\end{bmatrix}. \tag{30}\]  
The plane parameters \(p\) can be found by solving the least squares problem  
\[\min_{\hat{q}}\|Dq-E\|^{2}=\|Dp-E\|^{2}, \tag{31}\]  
the exact solution to the least squares task is:  
\[p=(D^{T}D)^{-1}D^{T}E. \tag{32}\]  
We denote by \(\Pi\) the plane defined by (29) and, (32). Note that \(Q_{c}\subset\Pi\).  
For a point \((x_{c},y_{c},z_{c})\in\Pi\) represented by the pixel coordinates \((\hat{u},\hat{v})\) in \(\hat{\Phi}\) we obtain, taking into account (6)  
\[\begin{array}{rcl}z_{c}&=&p_{z}-p_{x}x_{c}-p_{y}y_{c}\\ x_{c}/z_{c}&=&(\hat{u}-c_{u})/f_{u}\\ y_{c}/z_{c}&=&(\hat{v}-c_{v})/f_{v}\end{array}. \tag{33}\]  
If \(\hat{u}\
eq c_{u}\) and \(\hat{v}\
eq c_{v}\) (it means that \(x_{c}\
eq 0\) and \(y_{c}\
eq 0\)) then  
\[\begin{array}{rcl}p_{z}-p_{x}x_{c}-p_{y}y_{c}&=&x_{c}f_{u}/(\hat{u}-c_{u})\\ p_{z}-p_{x}x_{c}-p_{y}y_{c}&=&y_{c}f_{v}/(\hat{v}-c_{v})^{\prime},\end{array} \tag{34}\]  
so there are linear equations that allow us to express \(x_{c}\) and \(y_{c}\) through \(\hat{u}\) and \(\hat{v}\). Let  
\[\begin{array}{rcl}a(\hat{u})=f_{u}/(\hat{u}-c_{u})+p_{x}\\ b(\hat{v})=f_{v}/(\hat{v}-c_{v})+p_{y}\end{array}. \tag{35}\]  
From (34), we obtain solution:  
\[\begin{array}{rcl}\begin{bmatrix}x_{c}(\hat{u},\hat{v})\\ y_{c}(\hat{u},\hat{v})\end{bmatrix}=\begin{cases}p_{z}(p_{y}-b(\hat{v}))/(p_{x }p_{y}-a(\hat{u})b(\hat{v}))\\ p_{z}(p_{x}-a(\hat{u}))/(p_{x}p_{y}-a(\hat{u})b(\hat{v}))\end{cases},&\text{ if }\hat{u}\
eq c_{u},\hat{v}\
eq c_{v}\\ \begin{bmatrix}0\\ p_{z}/b(\hat{v})\end{bmatrix},&\text{ if }\hat{u}=c_{u},\hat{v}\
eq c_{v}\\ \begin{bmatrix}p_{z}/a(\hat{u})\\ 0\end{bmatrix},&\text{ if }\hat{u}\
eq c_{u}\,,\hat{v}=c_{v}\\ \begin{bmatrix}0\\ 0\end{bmatrix},&\text{ if }\hat{u}=c_{u}\,,\hat{v}=c_{v}\end{array}, \tag{36}\]  
where \(a(\hat{u})\) and \(b(\hat{v})\) defined in (35) and  
\[z_{c}(\hat{u},\hat{v})=p_{z}-p_{x}x_{c}(\hat{u},\hat{v})-p_{y}y_{c}(\hat{u}, \hat{v}). \tag{37}\]  
We have constructed a function that assigns to each pixel coordinates \(g=(\hat{u},\hat{v})\) (in image \(\hat{\Phi}\)) a spatial point in the coordinate system \(F_{c}\), according to (36) and (37):  
\[\xi(g)=\begin{bmatrix}x_{c}(\hat{u},\hat{v})\\ y_{c}(\hat{u},\hat{v})\\ z_{c}(\hat{u},\hat{v})\end{bmatrix}. \tag{38}\]\[\text{If}\ g\in\hat{Q}_{im}\ \xi(g)\in Q_{c},\ \text{so}\] \[Q_{c}=\xi(\hat{Q}_{im}), \tag{39}\] \[Q_{emu}=R^{T}Q_{c}+O=R^{T}\xi(\hat{Q}_{im})+O=R^{T}\xi(\Theta(Q_{im}))+O= \Lambda^{-1}(Q_{im}). \tag{40}\]  
Next, we will refer more to (39). \(F_{emu}\) helps obtain measurement results, but \(F_{c}\) is sufficient for calculating metric lengths. Here are other ways to map pixels to meters (see, e.g., [7] (pp. 47-55)), but their applicability depends on the data available.