# Cell-Based Target Localization and Tracking with an Active Camera
## 3 Methodology
### From Image Coordinates to World Coordinates  
We set the plane where the target object is located as the _XOY_ plane of the world coordinate system and set the z-axis as the straight line passing through point O and perpendicular to the _XOY_ plane. MN is the image of the target in the camera, as shown in Figure 2. The relationship between the real target and its image appeared as:  
\[Z_{c}\left[ \begin{array}{c}u\\ v\\ 1\end{array} \right]=K\left[ \begin{array}{cc}R&T\\ 0^{T}&1\end{array} \right]\left[ \begin{array}{c}X_{w}\\ Y_{w}\\ Z_{w}\\ 1\end{array} \right] \tag{7}\]  
Formula (7) is a classic formula for converting the world coordinate system to the image coordinate system. \(Z_{c}\) is the depth of the point \(p(u,v)\) in the camera coordinates, \(K\) is the internal parameter matrix of the camera, and \(R\) and \(T\) are the rotation and translation matrices of the camera coordinate system to the world coordinate system, respectively. When the target is running on the ground, the ground is set to the plane _XOY_, and the coordinates of the object on the ground in the world coordinate system are set to \((X_{w},Y_{w},0)\). Then, Formula (7) can also be expressed as:  
\[Z_{c}\left[ \begin{array}{c}u\\ v\\ 1\end{array} \right]=K\left[ \begin{array}{cc}R&T\\ 0^{T}&1\end{array} \right]\left[ \begin{array}{c}X_{w}\\ Y_{w}\\ 0\\ 1\end{array} \right] \tag{8}\]  
Given \(M\) as a \(3*3\) matrix, Formula (8) can be represented as follows:  
\[s\left[ \begin{array}{cc}u&v&1\end{array} \right]^{T}=M\left[ \begin{array}[] {cc}X_{w}&Y_{w}&1\end{array} \right]^{T} \tag{9}\]  
where \(M\) is the homography matrix and the \(M\) matrix has eight degrees of freedom. Therefore, at least four pairs of feature points are required to solve \(M\). Set the expression of the \(M\) matrix as follows:  
\[M=\left[ \begin{array}{ccc}m_{11}&m_{12}&m_{13}\\ m_{21}&m_{22}&m_{23}\\ m_{31}&m_{32}&m_{33}\end{array} \right] \tag{10}\]  
From Formulas (9) and (10), we can obtain:  
\[\left\{ \begin{array}{c}u=\frac{\frac{m_{11}}{m_{33}}X_{w}+\frac{m_{11}}{m_{1 }}Y_{w}+\frac{m_{11}}{m_{33}}}\\ \frac{m_{11}}{m_{33}}X_{w}+\frac{m_{11}}{m_{33}}Y_{w}+1\\ v=\frac{m_{11}}{m_{33}}X_{w}+\frac{m_{11}}{m_{33}}Y_{w}+1\end{array} \right. \tag{11}\]  
Given the \(M^{\prime}\) matrix as follows:  
\[M^{\prime}=\left[ \begin{array}{cccccc}\frac{m_{11}}{m_{33}}&\frac{m_{12}}{m_ {33}}&\frac{m_{13}}{m_{33}}&\frac{m_{21}}{m_{33}}&\frac{m_{22}}{m_{33}}&\frac{ m_{31}}{m_{33}}&\frac{m_{22}}{m_{33}}&\frac{m_{31}}{m_{33}}&\frac{m_{22}}{m_{33}} \end{array} \right]^{T} \tag{12}\]  
Then, Formula (12) can be expressed as:  
\[\left[ \begin{array}{cccccc}X_{w}&Y_{w}&1&0&0&0&-uX_{w}&-uX_{w}\\ 0&0&X_{w}&Y_{w}&1&-vX_{w}&-vY_{w}\end{array} \right]M^{\prime}=\left[ \begin{array} []{c}u\\ v\end{array} \right] \tag{13}\]  
Formula (13) can be regarded as \(PM^{\prime}=t\), which can be solved by the least square method:  
\[M^{\prime}=\left(P^{T}p\right)^{-1}p^{T}t \tag{14}\]  
Furthermore, the homography matrix can be obtained without solving the camera's internal and external parameters. \(M\) can be obtained by \(M^{\prime}\), Formulas (10) and (12). As shown in Figure 7, in the camera's perspective, the image of the red target on the _XOY_ plane is ABCD, but in actual situations, the projection of the target on the _XOY_ plane is ABFG. As a result, the quadrilateral ABCD and the quadrilateral ABFG are quite different. When the YOLOv4 algorithm is used to identify the target, the bounding box of the identified target is shown in Figure 7. The center point of the green bounding box representing the target position deviates further from the target's true position. Therefore, this paper proposes a position compensation method. The error value of the target at that point is subtracted to obtain the precise position of the target. The specific method is shown in Figure 8.  
Two projection models were constructed to calculate the target position. The first projection model is the position model, and the second is the error model.