Green check
Link copied to clipboard

Ultralytics YOLOv8 for Smarter Parking Management Systems

The Ultralytics YOLOv8 model can make parking management systems smarter. Learn to manage parking spaces in real-time to create your own smart parking solution.

It can be stressful to drive around in circles looking for a parking spot, especially when you are running late. The traditional way of searching for a place to park can be tedious and time-consuming. However, a parking management system driven by artificial intelligence (AI) and computer vision can make things simpler. It can make parking availability more predictable and reduce traffic congestion.

In this article, we’ll learn how to upgrade parking management systems with artificial intelligence and computer vision. We’ll also go through a step-by-step coding example to show you how you can use the Ultralytics YOLOv8 model to create a computer vision-enabled parking management system. Let’s dive right in!

Issues with Traditional Parking Lot Management

Before we discuss AI-enhanced smart parking management systems, let’s look at the issues with traditional parking management systems.

A major problem with traditional systems is overcrowded parking spaces; there are more cars in parking lots than available spaces. Besides wasting time looking for space, overcrowding leads to excess fuel consumption and air pollution. Another issue is driver stress. According to a survey, around 27% of people spend at least 30 minutes looking for parking spots. Also, 43% of people admitted to getting into verbal arguments with strangers over parking spots.

Fig 1. A stressed driver. Image source: Envato Elements.

AI Makes Parking Lot Management Easier

Parking lots integrated with AI aim to solve the issues traditional parking management systems face. Computer vision models like the Ultralytics YOLOv8 model and high-definition cameras can monitor parking lots and get real-time updates on available and occupied parking spaces. 

How does this work? A computer vision model can analyze footage from high-definition cameras to detect vehicles, track their movements, and identify available parking spots. The Ultralytics YOLOv8 model supports computer vision tasks like object detection and object tracking, and can accurately identify and classify vehicles within a video feed. By comparing the detected locations of the vehicles with the predefined parking spaces, the system can determine whether a parking space is occupied or not.

Fig 2. Parking Management using Ultralytics YOLOv8.

Information about parking availability from the vision-based system can be integrated and extended into different applications:

  • Mobile Apps: Mobile applications can display real-time parking availability and help drivers find available spots quickly and easily.
  • Digital Signage: Digital signs at parking lot entrances can show the number of available spaces and direct drivers to the nearest vacant spot.
  • Automated Parking Systems: The data can be used to control automated barriers and gates, allowing entry only when spaces are available and guiding drivers to the nearest free spot.

The Advantages of a Parking Management System

Insights into parking availability can provide many advantages. Real-time updates help drivers go directly to open spaces, making traffic flow smoother and reducing the stress of finding parking. For operators, understanding how spaces are used means they can better manage the lot, improve security with real-time monitoring, and quickly respond to any incidents.

Automating parking functions cuts costs by reducing the need for manual labor. AI systems make it easier to reserve parking spots through mobile or web apps, letting drivers receive notifications about availability and saving time and money. City planners can use this data to design better road layouts, enforce effective parking regulations, and develop new parking facilities that make cities more efficient and easier to navigate.

Fig 3. Reserve parking slots through a mobile app.

Try It Yourself: Parking Management Using YOLOv8

Now that we have a clear understanding of parking management and its advantages, let’s dive into how you can build a vision-based parking management system. We'll use the YOLOv8 model to detect vehicles, monitor parking spaces, and determine their occupancy status.

In this example, you can use a video or camera stream of a parking lot. Please note that this example's maximum supported image size is 1920 * 1080. Before we start, remember that this system relies on accurate vehicle detection and predefined parking space coordinates. 

Camera calibration and environmental factors can affect the accuracy of space detection and occupancy status. The processing speed and accuracy may also vary based on your GPU's performance.

Step 1: Let's begin by installing the Ultralytics package. Open your command prompt or terminal and execute the following command.


pip install ultralytics

Refer to our Ultralytics Installation guide for detailed instructions and best practices on the installation process. If you encounter any issues while installing the required packages for YOLOv8, our common issues guide offers solutions and helpful tips.

Step 2: We need to pre-select parking spots so that we can mark the areas of interest in your footage. Run this code to open the user interface to pre-select parking spots.


from ultralytics import solutions
solutions.ParkingPtsSelection()

As shown below, a user interface will open when you run this code. Take a frame or screenshot of your input video of a parking lot and upload it. After drawing bounding boxes around the parking spots, click the save option. Your selected parking spot information will be saved in a JSON file named ‘bounding_boxes.json.’

Fig 4. Selecting parking spots in your footage.

Step 3: Now, we can jump into the main code for parking management. Start by importing all the required libraries and initializing the JSON file we created in step 2.


import cv2
from ultralytics import solutions
polygon_json_path = "bounding_boxes.json"

Step 4: Create a VideoCapture object to read the input video file and make sure the video file is successfully opened.


cap = cv2.VideoCapture("Path/to/video/file.mp4")
assert cap.isOpened(), "Error reading video file"

Step 5: Initialize all the needed video properties, like the width, height, and frame per second.


w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH,
cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

Step 6: Next, we can create a VideoWriter object to save the final processed video file.


video_writer = cv2.VideoWriter("parking management.avi", 
cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h)) 

Step 7: Here, we initialize the parking management system with the Ultralytics YOLOv8 model for parking spot detection.


management = solutions.ParkingManagement(model_path="yolov8n.pt")  

Step 8: Now, we go through the video file, frame by frame, for processing. If no frames are read, the loop will break.


while cap.isOpened():
  ret, im0 = cap.read()
  if not ret:
    break

Step 9: Inside the loop, we will extract the pre-selected parking regions from the JSON file and track the objects in the frame using the YOLOv8 model.


json_data = management.parking_regions_extraction(polygon_json_path)   
results = management.model.track(im0, persist=True, show=False)

Step 10: This part of the loop processes the tracking results and obtains the bounding box coordinates and the class labels of the detected objects.


if results[0].boxes.id is not None:
  boxes = results[0].boxes.xyxy.cpu().tolist()
  clss = results[0].boxes.cls.cpu().tolist()
  management.process_data(json_data, im0, boxes, clss)

Step 11: The last part of the loop involves displaying the current frame with annotations and writing the processed frame to the output video file “parking management.avi.”


management.display_frames(im0)
video_writer.write(im0)

Step 12: Finally, we can release the VideoCapture and VideoWriter objects and destroy any windows.


cap.release()
video_writer.release()
cv2.destroyAllWindows()

Step 13: Save your script. If you are working from your terminal or command prompt, run the script using the following command:


python your_script_name.py

If the code is executed successfully, your output video file will look like this:

Fig 5. The Output of Parking Management Using YOLOv8.

Feel free to check out Ultralytics’ official docs if you’d like to learn more about the code.

Challenges of an Automated Parking Lot Management System

Intelligent parking systems offer many advantages to both drivers and businesses. However, they also present a few challenges that should be taken into account before implementing such solutions. Let’s take a look at some of them.

  • Privacy Concerns: These systems collect information such as the make and model of an individual’s car, license plate number, time of entry and exit, etc.
  • High Cost of Installation: Sensors, cameras, automated ticketing machines, and AI software can be expensive to install. 
  • Maintenance Requirements: The frequency of maintenance depends on the AI system, but most systems require monthly maintenance.

The Future of Smart Parking Systems

Innovative parking management in the future will be about using state-of-the-art technologies like AI, self-driving cars, and virtual reality to improve the overall parking experience and support sustainability. When integrated with these systems, self-driving cars will be able to navigate to parking locations without human interference and park. These systems also help businesses fill more parking spots and advertise their services across multiple apps and websites. They also reduce the number of carbon emissions that emanate from drivers driving around looking for a parking spot.

Ending Parking Hassles

AI models, like Ultralytics YOLOv8, and computer vision can transform your parking lot.  They dramatically cut down on circling for spots, saving you time and reducing emissions.  These smart parking management systems tackle common problems like congestion, illegal parking, and driver frustration. While there's an initial investment, the long-term benefits are significant. Investing in smart parking is key to creating sustainable cities and a smoother parking experience for everyone.

Want to learn more about AI? Connect with our community! Explore our GitHub repository to learn more about how we are using AI to create innovative solutions in various industries like healthcare and agriculture. Collaborate, innovate, and learn with us! 🚀

Facebook logoTwitter logoLinkedIn logoCopy-link symbol

Read more in this category

Let’s build the future
of AI together!

Begin your journey with the future of machine learning