Application of convolutional networks of the YOLO architecture for calculating free parking spaces in an arbitrary parking lot

. The paper describes the solution of the problem of automatic fixation of the availability of free parking spaces in parking lots based on the video stream of the surveillance camera. The problem was solved using a combination of the YOLOv7 model for detecting objects of interest of the "car" type, trained on a specially created training sample and grouping of objects using the k-means algorithm. The proposed solution has shown satisfactory accuracy and suitability for practical use in conditions of significant optical interference – daily light fluctuations and precipitation for calculating free parking spaces by the model without retraining it for various parking lots


Introduction
The use of computer vision tools for solving accounting problems in the course of enterprise management has now become widespread.It should also be noted the important role in intelligent transport and intelligent detection of road events of such a task as the detection and tracking of vehicles in the video stream of surveillance cameras.This is due to the requirements of reducing the cost of accounting and control operations and excluding subjective factors from their implementation, the influence of the skill level and discipline of a human observer.
In this paper, the solution of the problem of managing the placement of cars in an open parking lot will be considered.In order to provide effective support for the placement of cars, the following functional requirements were set before the system: The system should find all the cars in the parking lot corresponding to the surveillance camera.
The system should work at all heights of the location without retraining and reconfiguring the computer vision system.
The system should work in all seasons, day and night, also without retraining and reconfiguration.
The system should give out the number of free parking spaces in the parking lot.
The system should exclude from the calculation of free spaces areas in which cars cannot park or do not belong to the camera The issue of applying computer vision tools to the tasks of detecting, classifying and tracking vehicles, including parking management, is currently being considered in a large number of scientific studies.A detailed overview of the use of artificial vision systems in transport management tasks is given in [1].The authors of the work [2] used convolutional neural networks using Google Cloud Vision technology, modified on the basis of parking images collected from the KhNUParking dataset.The paper [3] considers the solution of the problem of vehicle detection and tracking based on computer vision for real-time scenarios based on the HOG method for feature extraction, an improvised correlation filter for tracking, and the AdaBoost model for object classification.The authors of the article [4] use an object detection algorithm based on a combination of YOLO and GhostNet architectures to control wheeled robots.Work [5] describes the application of a new approach based on convolutional neural networks to solving the problem of creating a hardware-efficient automated license plate recognition system for a limited environment with limited resources.
The authors of this work also investigated the possibilities of solving the problems of monitoring production sites and tracking vehicles using computer vision tools in their works [6], [7] and [8].
Thus, the solution of the task set in the work -monitoring the availability of free parking spaces in the parking lot -is important for improving the efficiency of parking and is relevant from the point of view of the tools used.

Materials
The data used for training and testing the system were obtained from 21 different scenes ob 22 served by security-type street cameras from the houses of the city of Krasnoyarsk in the period from winter to spring 2023.The cameras are installed at different heights and from different angles.The resolution of all images is the same type of 800x1440 pixels in RGB color resolution.
In the process of preparing the computer vision system training, 2623 images were marked up.The total number of samples of the "car" class in these images was 123795.For the stable operation of the system in various weather conditions, the training sample was accumulated gradually, currently the system is in the waiting stage for data collection of the summer season, when greenery will begin to appear on the images.
As the initial information, the recordings of the video stream from the surveillance camera of the security service of the weighing company were used.The original image obtained from the camera has a resolution of 1920 x 1080 pixels RGB format.

Creating a pseudo-map
According to the rules of the road [9] of the Russian Federation, the parking of a car is counted if the vehicle has stopped for longer than five minutes.The pseudo-parking map of the target house was built on the basis of a daily recording from a video surveillance camera.
In order to train the machine detector, an author's training dataset was developed, since the model previously trained on the VoCOCOv2017 dataset [10] could not give an achievable result on images obtained from security cameras.With the help of a trained detector built on a convolutional neural network of the YOLOv7 architecture [11], machines are located and the positions of their centroids are calculated.
Then, using the point tracker, the centroids of moving objects with a threshold of 5 minutes are discarded.After filtering the moving objects, the nearest centroids were averaged using the k-means method, the number of clusters was assumed to be equal to the maximum number of cars detected in the video.This point was the center of the parking space in the resulting pseudo-map of the target building.
The scheme of the algorithm is shown in Figure 1 Fig. 1 Formation of a parking plan camera To visualize the parking space area, the task of displaying averaged frames limiting the area of the location of cars obtained during the detection of the positions of cars by the detector model was solved.To filter out areas that are not related to the target building on which the camera is installed, the possibility of selecting a zone of interest was implemented.

Counting free parking spaces
After creating a pseudo-map of the target parking, the system can calculate the available and occupied parking spaces.Once a minute, the system receives a frame from a surveillance camera and detects cars using a detector.If the centroid of the parking space is located in the bounding box of the detected car, it is assumed that the parking space is occupied and marked with a red label.Otherwise, the place is free and is marked with a green label.

Results
A model based on the YOLOv7 architecture was trained on an NVIDIA GeForce 2060ti video card for 6 hours.
The results show that the network has been trained successfully and it can be used on scenes with a similar camera location (Table 1) The graph (see Figure 2) shows the values of the val oss and mAP metrics during training.Figure 3 shows the results of detection by the YOLOv7 model of all frames of a daily video fragment recorded for the construction of a pseudo-map.As can be seen in the test image, static objects and centroids of moving objects are defined.Fig. 3. Obtaining all centroids of the "car" class using a detector based on the YOLOv7 architecture Since the task of the system is to form a map of user parking from the camera, it is necessary to solve the problem of excluding from the map the centroids of those objects whose points are distant from each other in the interval of 5-7 pixels.Figure 4 shows filtered centroids of static objects.After applying the algorithm for grouping objects by the k-mean elements method, new coordinates of the centroid corresponding to the positions of the centers of individual parking spaces are stored in the system.Figure 5 shows the result of applying the centroid filter.At the next step, after receiving the primary pseudo-map, it is necessary to solve the problem of zoning individual parking spaces.To do this, the values of the detector's bounding box are taken, collected from the test daily video, and then the value of the frame coordinates is averaged using the k-means method and new X, Y bouding coordinates are determined.Figure 5 shows the averaged boundaries of a separate parking space in blue.This task is necessary to determine the status of a separate parking space: free or occupied space by a car.After receiving the finished pseudo-card, the system is able to determine the number of free and occupied parking spaces in real time.To do this, the detector determines the zone of interest, while the camera closest to the parking lot is the target zone.In Figure 10, the parking area related to the camera "April 6, facade" is marked in blue.In this zone, the system should not issue errors.After fixing the target area for the current camera, the system is able to determine the status of a separate parking space.To do this, once every five minutes, an image from the camera is fed to the input of the algorithm and the detector captures centroids and bounding frames of objects of the "machine" type.If the frame or center intersects the bounding box of a separate parking space, the system considers that this place is inaccessible.

Conclusion
During development, we managed to solve all the tasks set and successfully put into operation a system for tracking vacant spaces in images obtained from cameras located at different heights and at different angles, as well as in different natural conditions, including snow and night shots with various optical defects.

E3SFig. 2 .
Fig. 2. The YOLO v7 training graphic is based on the collected data.

Fig. 6 .
Fig. 6.Example of averaging rectangles bounding machines After getting the coordinates of all parking spaces, the algorithm knows a fixed number of parking spaces.Figures 7, 8 and 9 show the calculated parking spaces on different surveillance cameras.

Fig. 10 .
Fig. 10.The responsibility card of the camera at the address Krasnoyarsk, Aprelskaya str.6I Figures 11  show the final results of the system.

Fig. 11 .
Fig. 11.Calculation and visualization of free and occupied parking spaces on a video surveillance camera at the address Krasnoyarsk, Aprelskaya str., 6b (in the courtyard)

Table 1 .
YOLOv7 Model Training Accuracy Metrics