Reference for ultralytics/solutions/parking_management.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/parking_management.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.solutions.parking_management.ParkingPtsSelection
ParkingPtsSelection()
A class for selecting and managing parking zone points on images using a Tkinter-based UI.
This class provides functionality to upload an image, select points to define parking zones, and save the selected points to a JSON file. It uses Tkinter for the graphical user interface.
Attributes:
Name | Type | Description |
---|---|---|
tk |
module
|
The Tkinter module for GUI operations. |
filedialog |
module
|
Tkinter's filedialog module for file selection operations. |
messagebox |
module
|
Tkinter's messagebox module for displaying message boxes. |
master |
Tk
|
The main Tkinter window. |
canvas |
Canvas
|
The canvas widget for displaying the image and drawing bounding boxes. |
image |
Image
|
The uploaded image. |
canvas_image |
PhotoImage
|
The image displayed on the canvas. |
rg_data |
List[List[Tuple[int, int]]]
|
List of bounding boxes, each defined by 4 points. |
current_box |
List[Tuple[int, int]]
|
Temporary storage for the points of the current bounding box. |
imgw |
int
|
Original width of the uploaded image. |
imgh |
int
|
Original height of the uploaded image. |
canvas_max_width |
int
|
Maximum width of the canvas. |
canvas_max_height |
int
|
Maximum height of the canvas. |
Methods:
Name | Description |
---|---|
initialize_properties |
Initialize properties for image, canvas, bounding boxes, and dimensions. |
upload_image |
Upload and display an image on the canvas, resizing it to fit within specified dimensions. |
on_canvas_click |
Handle mouse clicks to add points for bounding boxes on the canvas. |
draw_box |
Draw a bounding box on the canvas using the provided coordinates. |
remove_last_bounding_box |
Remove the last bounding box from the list and redraw the canvas. |
redraw_canvas |
Redraw the canvas with the image and all bounding boxes. |
save_to_json |
Save the selected parking zone points to a JSON file with scaled coordinates. |
Examples:
>>> parking_selector = ParkingPtsSelection()
>>> # Use the GUI to upload an image, select parking zones, and save the data
Source code in ultralytics/solutions/parking_management.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
draw_box
draw_box(box: List[Tuple[int, int]])
Draw a bounding box on the canvas using the provided coordinates.
Source code in ultralytics/solutions/parking_management.py
142 143 144 145 |
|
initialize_properties
initialize_properties()
Initialize properties for image, canvas, bounding boxes, and dimensions.
Source code in ultralytics/solutions/parking_management.py
102 103 104 105 106 107 |
|
on_canvas_click
on_canvas_click(event)
Handle mouse clicks to add points for bounding boxes on the canvas.
Source code in ultralytics/solutions/parking_management.py
133 134 135 136 137 138 139 140 |
|
redraw_canvas
redraw_canvas()
Redraw the canvas with the image and all bounding boxes.
Source code in ultralytics/solutions/parking_management.py
155 156 157 158 159 160 |
|
remove_last_bounding_box
remove_last_bounding_box()
Remove the last bounding box from the list and redraw the canvas.
Source code in ultralytics/solutions/parking_management.py
147 148 149 150 151 152 153 |
|
save_to_json
save_to_json()
Save the selected parking zone points to a JSON file with scaled coordinates.
Source code in ultralytics/solutions/parking_management.py
162 163 164 165 166 167 168 169 170 171 172 173 |
|
upload_image
upload_image()
Upload and display an image on the canvas, resizing it to fit within specified dimensions.
Source code in ultralytics/solutions/parking_management.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
ultralytics.solutions.parking_management.ParkingManagement
ParkingManagement(**kwargs: Any)
Bases: BaseSolution
Manages parking occupancy and availability using YOLO model for real-time monitoring and visualization.
This class extends BaseSolution to provide functionality for parking lot management, including detection of occupied spaces, visualization of parking regions, and display of occupancy statistics.
Attributes:
Name | Type | Description |
---|---|---|
json_file |
str
|
Path to the JSON file containing parking region details. |
json |
List[Dict]
|
Loaded JSON data containing parking region information. |
pr_info |
Dict[str, int]
|
Dictionary storing parking information (Occupancy and Available spaces). |
arc |
Tuple[int, int, int]
|
RGB color tuple for available region visualization. |
occ |
Tuple[int, int, int]
|
RGB color tuple for occupied region visualization. |
dc |
Tuple[int, int, int]
|
RGB color tuple for centroid visualization of detected objects. |
Methods:
Name | Description |
---|---|
process |
Process the input image for parking lot management and visualization. |
Examples:
>>> from ultralytics.solutions import ParkingManagement
>>> parking_manager = ParkingManagement(model="yolo11n.pt", json_file="parking_regions.json")
>>> print(f"Occupied spaces: {parking_manager.pr_info['Occupancy']}")
>>> print(f"Available spaces: {parking_manager.pr_info['Available']}")
Source code in ultralytics/solutions/parking_management.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
process
process(im0: ndarray) -> SolutionResults
Process the input image for parking lot management and visualization.
This function analyzes the input image, extracts tracks, and determines the occupancy status of parking regions defined in the JSON file. It annotates the image with occupied and available parking spots, and updates the parking information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im0
|
ndarray
|
The input inference image. |
required |
Returns:
Type | Description |
---|---|
SolutionResults
|
Contains processed image |
Examples:
>>> parking_manager = ParkingManagement(json_file="parking_regions.json")
>>> image = cv2.imread("parking_lot.jpg")
>>> results = parking_manager.process(image)
Source code in ultralytics/solutions/parking_management.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|