# Two-Stage Efficient Parking Space Detection Method Based on Deep Learning and Computer Vision
## 2 Research Content
### Parking Space Inference  
When \(\mathcal{P}_{n}\) and \(\mathcal{P}_{m}\) can form the entrance of a parking space, assume that the coordinates of \(\mathcal{P}_{n}\) and \(\mathcal{P}_{m}\) on the original image are \((x_{n},y_{n})\) and \((x_{m},y_{m})\), respectively, the vector \(\overrightarrow{\mathcal{P}_{n}\mathcal{P}_{m}}\) is the feasible entrance line of the parking space, the local coordinate system is constructed with the midpoint \(\left(\frac{x_{n}+x_{m}}{2},\frac{y_{n}+y_{m}}{2}\right)\) of \(\mathcal{P}_{n}\) and \(\mathcal{P}_{m}\), and \(\frac{\mathcal{P}_{n}\mathcal{P}_{m}}{|\mathcal{P}_{n}\mathcal{P}_{m}|}\) is a basis vector of the local coordinate system, expressed as \(\overset{\rightarrow}{a}=\left(\frac{x_{n}-x_{n}}{\sqrt{\left(x_{n}-x_{n} \right)^{2}+\left(y_{m}-y_{n}\right)^{2}}},\frac{y_{n}-y_{n}}{\sqrt{\left(x_{n }-x_{n}\right)^{2}+\left(y_{m}-y_{n}\right)^{2}}}\right)\). Construct a space cartesian coordinate system with the normal vector \(\overset{\rightarrow}{b}=\left(-\frac{y_{n}-y_{n}}{\sqrt{\left(x_{n}-x_{n} \right)^{2}+\left(y_{m}-y_{n}\right)^{2}}},\frac{x_{n}-x_{n}}{\sqrt{\left(x_{n }-x_{n}\right)^{2}+\left(y_{m}-y_{n}\right)^{2}}}\right)\) of vector \(\overset{\rightarrow}{a}\) as another basis, and the normal vector passing through point \(\mathcal{P}_{n}\) and perpendicular to vector \(\overset{\rightarrow}{a}\) is expressed as follows:  
\[\overset{\rightarrow}{c}=L(i,j)\times(x_{n}\quad-\frac{y_{n}-y_{n}}{\sqrt{ \left(x_{m}-x_{n}\right)^{2}+\left(y_{m}-y_{n}\right)^{2}}}-x_{n},y_{n} \tag{3}\] \[\quad+\frac{x_{n}-x_{n}}{\sqrt{\left(x_{m}-x_{n}\right)^{2}+\left( y_{m}-y_{n}\right)^{2}}}-y_{n})\]  
By the same token, the expression for a normal vector passing through \(\mathcal{P}_{m}\) and perpendicular to the vector \(\overset{\rightarrow}{a}\) is  
\[\overset{\rightarrow}{d}=L(i,j)\times(x_{m}-\frac{y_{m}-y_{n}}{\sqrt{\left(x _{m}-x_{n}\right)^{2}+\left(y_{m}-y_{n}\right)^{2}}}-x_{m},y_{m}+\frac{x_{m}-x _{n}}{\sqrt{\left(x_{m}-x_{n}\right)^{2}+\left(y_{m}-y_{n}\right)^{2}}}-y_{m}) \tag{4}\]  
where \(L(i,j)\) is used to specify the direction of vectors \(\overset{\rightarrow}{c}\) and \(\overset{\rightarrow}{d}\). If the parking space direction is counterclockwise, the vector direction is left; if the parking space direction is clockwise, the vector direction is right. According to prior knowledge, the length of the entrance line of the horizontal parking space is \(\lambda_{1}\), the width of the horizontal parking space is \(\lambda_{2}\), the length of the entrance line of the vertical parking space is \(\mu_{1}\), the width of the vertical parking space is \(\mu_{2}\), and each parking space can be represented by four vectors. The entrance line of the horizontal parking space is the vector \(\lambda_{1}\overset{\rightarrow}{a}\), originating from \(\mathcal{P}_{n}\). The width of the horizontal parking space is represented by the vectors \(\lambda_{2}\overset{\rightarrow}{c}\) and \(\lambda_{2}\overset{\rightarrow}{d}\), originating from \(\mathcal{P}_{n}\) and \(\mathcal{P}_{m}\), respectively. The coordinates of points \(\mathcal{P}_{n}\) and \(\mathcal{P}_{m}\) in the local coordinate system are, respectively, (\(-\frac{\sqrt{\left(x_{m}-x_{n}\right)^{2}+\left(y_{m}-y_{n}\right)^{2}}}{2}\),0) and (\(\frac{\sqrt{\left(x_{m}-x_{n}\right)^{2}+\left(y_{m}-y_{n}\right)^{2}}}{2}\),0). In reality, the parking space is composed of two parallel lines, and the vector parallel to the entrance line of the parking space can be expressed in the local coordinate system as points \(\zeta_{a}=\left(-\frac{\sqrt{\left(x_{m}-x_{n}\right)^{2}+\left(y_{m}-y_{n} \right)^{2}}}{2},\frac{L(i,j)\lambda_{1}}{)}\), serving as the starting point.