Coder Social home page Coder Social logo

automatic-ambulance-detection-system-for-emergency-vehicle-prioritization-using-image-processing's Introduction

AUTOMATIC-AMBULANCE-DETECTION-SYSTEM-FOR-EMERGENCY-VEHICLE-PRIORITIZATION-USING-IMAGE-PROCESSING

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.

FEATURES USED:

  1. Real-time ambulance detection
  2. Traffic signal control

REQUIREMENTS :

  1. PYTHON
  2. Required Libraries : a. YOLO from Ultralytics b. Open Source Computer Vision c. Tkinter

ARCHITECTURE DIAGRAM :

image

FLOW DIAGRAM :

FLOW

INSTALLATIONS

INSTALL THE REQUIRED PACKAGES

    from ultralytics import YOLO

    import cv2

    import tkinter as tk

DOWNLOADING THE IMAGE DATASET

We use Open image dataset for downloading image datasets of Ambulance

ANNOTATE THE IMAGES IN DATASET

For annotating the images for training the dataset we use Roboflow .

USAGE

1. Collect the dataset .

2. Annotate the images .

3. Train the images using YOLO .

4. Detect the ambulance in the given video .

5. Show a Green signal after the Ambulance is detected .

6. End of the Program .

PROGRAM

1. YOLO CODE TO TRAIN IMAGE DATASET


from ultralytics import YOLO
import cv2

model = YOLO("yolov8n.yaml")

results = model.train(data="D:/code/data.yaml", epochs=30)

2. CODE TO PREDICT AMBULANCE IN VIDEO


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()

OUTPUT

AMBULANCE DETECTED

image

TRAFFIC LIGHT : GREEN ( AFTER DETECTED )

image

RESULT

  1. An automatic ambulance detection system using image processing techniques has been developed to enhance emergency response times and improve traffic management efficiency.

  2. 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.

  3. The successful implementation of this system holds the potential to revolutionize emergency response protocols and save lives.

automatic-ambulance-detection-system-for-emergency-vehicle-prioritization-using-image-processing's People

Contributors

s-abhishek-1905 avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

pavizhi

automatic-ambulance-detection-system-for-emergency-vehicle-prioritization-using-image-processing's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.