This project focuses on developing an automatic ambulance detection system using YOLO (You Only Look Once) image processing to prioritize emergency vehicles in traffic. The system detects ambulances in real-time through camera feeds, enabling traffic lights to give them the right-of-way immediately. By automating the detection and prioritization process, it reduces delays for emergency vehicles, ensuring faster response times. The system's integration into existing traffic management infrastructure enhances overall traffic flow and safety. This innovative approach contributes to more efficient urban traffic management and better emergency services.
- Real-time ambulance detection
- Traffic signal control
- PYTHON
- Required Libraries : a. YOLO from Ultralytics b. Open Source Computer Vision c. Tkinter
from ultralytics import YOLO
import cv2
import tkinter as tk
We use Open image dataset for downloading image datasets of Ambulance
For annotating the images for training the dataset we use Roboflow .
from ultralytics import YOLO
import cv2
model = YOLO("yolov8n.yaml")
results = model.train(data="D:/code/data.yaml", epochs=30)
import cv2
from ultralytics import YOLO
import tkinter as tk
# Define the input video path or use a webcam (0)
video_path = "D:/PAA/videos/ambu1.mp4" # Replace with your video path or set to 0 for webcam
# Load the trained YOLO model
model = YOLO("D:/PAA/runs/detect/train3/weights/best.pt") # Replace with your model path
# Define the threshold for object detection
threshold = 0.5
window = tk.Tk()
window.title("Ambulance Detection Traffic Light")
# Create the traffic light frame
traffic_light_frame = tk.Frame(window, bg="green", width=100, height=100)
traffic_light_frame.pack()
def detect_ambulance():
global light_on
# Simulate ambulance detection by changing the light color to green
light_on = "green"
traffic_light_frame.config(bg=light_on)
# Open the video stream or capture from a live camera
if video_path:
cap = cv2.VideoCapture(video_path) # For video file
else:
cap = cv2.VideoCapture(0) # For live camera
while True:
# Read the next frame from the video stream
ret, frame = cap.read()
# Detect objects in the frame using YOLO
results = model(frame)[0]
# Draw bounding boxes and labels around detected objects
for result in results.boxes.data.tolist():
x1, y1, x2, y2, score, class_id = result
if score > threshold and class_id == 0: # Check if class_id corresponds to ambulance
cv2.rectangle(frame, (int(x1), int(y1)), (int(x2), int(y2)), (0, 255, 0), 4)
cv2.putText(frame, "Ambulance Detected", (int(x1), int(y1 - 10)),
cv2.FONT_HERSHEY_SIMPLEX, 1.3, (0, 255, 0), 3, cv2.LINE_AA)
window.after(5000, detect_ambulance)
window.mainloop()
# Display the resulting frame with detected objects
cv2.imshow("Ambulance Detection", frame)
# Break the loop if the 'q' key is pressed
if cv2.waitKey(1) & 0xFF == ord("q"):
break
# Release the video capture and close all windows
cap.release()
cv2.destroyAllWindows()
-
An automatic ambulance detection system using image processing techniques has been developed to enhance emergency response times and improve traffic management efficiency.
-
The system accurately identifies and localizes ambulances in real-time video streams using a combination of background subtraction, object segmentation, feature extraction, and machine learning techniques.
-
The successful implementation of this system holds the potential to revolutionize emergency response protocols and save lives.