# Two-Stage Efficient Parking Space Detection Method Based on Deep Learning and Computer Vision
## 2 Research Content
### Local Image Discrimination
Figure 5a shows the clockwise direction of the vertical parking space, Figure 5b shows the counterclockwise direction of the vertical parking space, and Figure 5c shows the clockwise direction of the horizontal parking space. The purpose of differentiating parking spaces into these four categories is to prevent errors in Figure 4d. In the subsequent inference of parking spaces, the rotation of parking spaces must be known to determine the direction of the normal vector perpendicular to the entrance line of the parking space. To identify these four types of parking spaces, we can solve the problem by identifying the target box containing \(\text{P}_{i}\) points. In this paper, a convolutional kernel \(K\) of \(p\times p\) with the same size as the real border is constructed. In Figure 6a, we show this convolution kernel. The values of the left half of the convolution kernel are all \(-1\), and the values of the right half are all \(1\). It is worth noting that the values of \(1\) and \(-1\) of the convolution kernel are freely defined by the author. Of course, \(1\) can be changed to other positive numbers A, and \(-1\) can be changed to other negative numbers \(-\)A. After the modification, the entire calculation result is A times different from the calculation result obtained using \(1\) and \(-1\), but the final result has the same positive and negative values, and the rotation direction of the identified parking space is also unchanged. However, it should be noted that the two numbers used should be opposite to each other to ensure the accuracy of the calculation results. Before the rotation detection of parking space, it is necessary to transform the image obtained by the key point detector D into a grayscale image, as shown in Figure 6b, and before converting the image to grayscale, the original 56 \(\times\) 56 image should be resized to the standard size of 112 \(\times\) 112 to achieve better results. YoloV11 extracts the target frame containing the key points. In the subsequent operations, linear interpolation is used to enlarge the image to a resolution of 126 \(\times\) 126. Noise may appear at the boundaries of the parking space, so average filtering is applied to the grayscale image to remove irregularities around the parking lines, making the image smoother, as shown in Figure 6c. Specifically, the average filtering process with a convolution kernel size of 7 \(\times\) 7 is used to further smooth the image based on Figure 6b. Then, transform the grayscale image into a binary image I by using the Otsu method, as shown in Figure 6d, to transform the gray image into a binary image. Finally, the convolution operation \(J(i,j)=(I*K)(i,j)\) is carried out by using the defined convolution kernel \(K\) and the processed binarization image \(I\). Figure 6d represents a clockwise rotation, Figure 6e represents a counterclockwise rotation, and Figure 6f simulates the binary image of Figure 6e using a 10 \(\times\) 10 matrix. The matrix in Figure 6f is convolved, with the convolution kernel used to determine the direction of rotation. The final result is 15 \(\times\) 255, which leads to the conclusion that Figure 6e exhibits counterclockwise rotation. When the key points of the parking spaces that form the entrance lines of two parking spaces are obtained, along with the rotation directions of these key points, we can connect the two key points, then use the rotation direction to determine the normal vector of the parking space entrance line. The normal vector should point toward the inside of the parking space, allowing for the accurate localization of the parking space. \[L(i,j)= \begin{cases}-1,\ J(i,j)<0\\ 1,\ J(i,j)\geq 0\end{cases}  \tag{2}\]  
When the function \(J(i,j)\geq 0\), the parking space is in the counterclockwise direction. When the function \(J(i,j)<0\), the parking space is in the clockwise direction. In addition, the function \(L(i,j)\) is the identification function of the rotation direction of the parking space. The whole local image discrimination involves three steps.