Optimize parking management solution (#16288)

Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
Co-authored-by: Ultralytics Assistant <135830346+UltralyticsAssistant@users.noreply.github.com>
This commit is contained in:
Muhammad Rizwan Munawar 2024-09-17 23:27:03 +05:00 committed by GitHub
parent 6f2bb65953
commit 6e3b7dc2f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 92 additions and 133 deletions

View file

@ -74,9 +74,6 @@ Parking management with [Ultralytics YOLOv8](https://github.com/ultralytics/ultr
from ultralytics import solutions
# Path to json file, that created with above point selection app
polygon_json_path = "bounding_boxes.json"
# Video capture
cap = cv2.VideoCapture("Path/to/video/file.mp4")
assert cap.isOpened(), "Error reading video file"
@ -86,22 +83,16 @@ Parking management with [Ultralytics YOLOv8](https://github.com/ultralytics/ultr
video_writer = cv2.VideoWriter("parking management.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
# Initialize parking management object
management = solutions.ParkingManagement(model_path="yolov8n.pt")
parking_manager = solutions.ParkingManagement(
model="yolov8n.pt", # path to model file
json_file="bounding_boxes.json", # path to parking annotations file
)
while cap.isOpened():
ret, im0 = cap.read()
if not ret:
break
json_data = management.parking_regions_extraction(polygon_json_path)
results = management.model.track(im0, persist=True, show=False)
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)
management.display_frames(im0)
im0 = parking_manager.process_data(im0)
video_writer.write(im0)
cap.release()
@ -111,14 +102,12 @@ Parking management with [Ultralytics YOLOv8](https://github.com/ultralytics/ultr
### Optional Arguments `ParkingManagement`
| Name | Type | Default | Description |
| ------------------------ | ------- | ----------------- | -------------------------------------- |
| `model_path` | `str` | `None` | Path to the YOLOv8 model. |
| `txt_color` | `tuple` | `(0, 0, 0)` | RGB color tuple for text. |
| `bg_color` | `tuple` | `(255, 255, 255)` | RGB color tuple for background. |
| `occupied_region_color` | `tuple` | `(0, 255, 0)` | RGB color tuple for occupied regions. |
| `available_region_color` | `tuple` | `(0, 0, 255)` | RGB color tuple for available regions. |
| `margin` | `int` | `10` | Margin for text display. |
| Name | Type | Default | Description |
| ------------------------ | ------- | ------------- | -------------------------------------------------------------- |
| `model` | `str` | `None` | Path to the YOLOv8 model. |
| `json_file` | `str` | `None` | Path to the JSON file, that have all parking coordinates data. |
| `occupied_region_color` | `tuple` | `(0, 0, 255)` | RGB color for occupied regions. |
| `available_region_color` | `tuple` | `(0, 255, 0)` | RGB color for available regions. |
### Arguments `model.track`