repo logo
Construction-Hazard-Detection
Language
Python
Created
01/02/2024
Last updated
09/16/2024
License
GNU Affero General Public License v3.0
autowiki
Software Version
u-0.0.1Basic
Generated from
Commit
5f810b
Generated on
09/17/2024

Construction-Hazard-Detection
[Edit section]
[Copy link]

• • •
Architecture Diagram for Construction-Hazard-Detection
Architecture Diagram for Construction-Hazard-Detection

The Construction-Hazard-Detection repository provides a system for automatically detecting and monitoring safety hazards on construction sites using AI-powered object detection and real-time video analysis. It helps construction managers and safety officers identify potential risks and ensure compliance with safety regulations.

The core functionality of the system is built around the YOLOv8 object detection model, which is used to identify various objects and potential hazards in construction site video streams. The main components of the system include:

• Object detection and hazard identification: The DangerDetector class analyzes detected objects to identify potential hazards such as workers without safety gear, workers in controlled areas, or workers in close proximity to machinery. For more details on the hazard detection logic, see the Hazard Detection Logic section.

• Real-time video processing: The StreamCapture and LiveStreamDetector classes handle the capture and processing of video streams from construction sites. The system can process multiple streams simultaneously and adapt to varying internet speeds. More information can be found in the Real-Time Video Stream Processing section.

• Notification system: When hazards are detected, the system can send alerts through various messaging platforms including LINE, Facebook Messenger, Telegram, and WeChat. This functionality is implemented in separate notifier classes for each platform. The Notification System section provides more details on this feature.

• Web-based monitoring interface: A Flask-based web application allows users to view live video streams and detection results in real-time. The implementation details are covered in the Web-Based Monitoring Interface section.

The system also includes tools for data augmentation, model training, and evaluation:

• The …/YOLOv8_data_augmentation directory contains scripts for applying various image augmentation techniques to enhance the training dataset.

• The …/YOLOv8_train directory provides scripts for training, validating, and exporting YOLOv8 models.

• The …/YOLOv8_evaluation directory contains tools for evaluating model performance using metrics such as Average Precision and mean Average Precision (mAP).

Key design choices in the implementation include:

  1. Modular architecture: The system is divided into separate components for video capture, object detection, hazard analysis, and notification, allowing for easy maintenance and extensibility.

  2. Flexibility in deployment: The system can be run in a Docker environment or a Python environment, with instructions provided for both setups.

  3. Configurable video streams: Users can specify details of video streams, including URL, image name, label, and machine learning model, through a YAML configuration file.

  4. Automated model management: The system includes functionality for downloading pre-trained models and periodically updating them to ensure the latest versions are used.

For developers looking to extend or customize the system, the …/YOLOv8_server_api directory provides a Flask-based API for object detection, which can be integrated into other applications or services.

Object Detection and Hazard Identification
[Edit section]
[Copy link]

References: src, examples/YOLOv8_evaluation, examples/YOLOv8_train

• • •
Architecture Diagram for Object Detection and Hazard Identification
Architecture Diagram for Object Detection and Hazard Identification

The YOLOModelHandler class in …/train.py serves as the central component for managing YOLO (You Only Look Once) models. It provides methods for:

Read more

YOLOv8 Model Training and Evaluation
[Edit section]
[Copy link]

References: examples/YOLOv8_train, examples/YOLOv8_evaluation

• • •
Architecture Diagram for YOLOv8 Model Training and Evaluation
Architecture Diagram for YOLOv8 Model Training and Evaluation

The YOLOModelHandler class in …/train.py manages the training and evaluation of YOLOv8 models for construction hazard detection. Key functionalities include:

Read more

Real-time Object Detection and Tracking
[Edit section]
[Copy link]

References: src

• • •
Architecture Diagram for Real-time Object Detection and Tracking
Architecture Diagram for Real-time Object Detection and Tracking

The LiveStreamDetector class in …/live_stream_detection.py handles real-time object detection and tracking using YOLOv8 with SAHI (Sliced and Hierarchical Inference). Key features include:

Read more

Real-Time Video Stream Processing
[Edit section]
[Copy link]

References: src/stream_capture.py, src/live_stream_detection.py, src/live_stream_tracker.py

• • •
Architecture Diagram for Real-Time Video Stream Processing
Architecture Diagram for Real-Time Video Stream Processing

The StreamCapture class in …/stream_capture.py handles real-time video stream processing. Key features include:

Read more

Visualization of Safety Measures
[Edit section]
[Copy link]

References: src/drawing_manager.py

• • •
Architecture Diagram for Visualization of Safety Measures
Architecture Diagram for Visualization of Safety Measures

The DrawingManager class in …/drawing_manager.py is responsible for the visual representation of safety measures on video frames. It provides a set of methods to enhance the visibility of potential hazards and safety equipment, which is crucial for quick identification and response by safety personnel monitoring construction sites.

Read more

Localization of Warning Messages
[Edit section]
[Copy link]

References: src/danger_detector.py, src/lang_config.py

• • •
Architecture Diagram for Localization of Warning Messages
Architecture Diagram for Localization of Warning Messages

The DangerDetector class is equipped with a get_text() method that retrieves localized warning messages based on the current language setting. This method is crucial for providing clear communication to users in their preferred language, enhancing the usability of the hazard detection system across different regions. The localization process involves the following steps:

Read more

Real-Time Monitoring and Notification
[Edit section]
[Copy link]

References: src, examples/streaming_web

• • •
Architecture Diagram for Real-Time Monitoring and Notification
Architecture Diagram for Real-Time Monitoring and Notification

The LiveStreamDetector class in …/live_stream_tracker.py handles real-time video stream processing and object detection. Key functionality includes:

Read more

Stream Capture and Processing
[Edit section]
[Copy link]

References: src/stream_capture.py

• • •
Architecture Diagram for Stream Capture and Processing
Architecture Diagram for Stream Capture and Processing

The StreamCapture class in …/stream_capture.py handles real-time video stream capture and processing. Key features include:

Read more

WebSocket Communication and Event Handling
[Edit section]
[Copy link]

References: examples/streaming_web/static/js/label.js

• • •
Architecture Diagram for WebSocket Communication and Event Handling
Architecture Diagram for WebSocket Communication and Event Handling

In the Construction-Hazard-Detection project, the …/label.js file plays a crucial role in managing real-time communication between the server and the client's web interface. The implementation leverages the WebSocket protocol to facilitate a continuous stream of data, which is essential for the live monitoring of construction sites.

Read more

Redis Integration for Data Management
[Edit section]
[Copy link]

References: examples/streaming_web/app.py

• • •
Architecture Diagram for Redis Integration for Data Management
Architecture Diagram for Redis Integration for Data Management

Redis is utilized for managing and distributing captured stream data in the construction hazard detection system. The Redis connection is configured using environment variables for the host, port, and password, allowing for flexible deployment across different environments.

Read more

Data Augmentation and Model Training
[Edit section]
[Copy link]

References: examples/YOLOv8_data_augmentation, examples/YOLOv8_train

• • •
Architecture Diagram for Data Augmentation and Model Training
Architecture Diagram for Data Augmentation and Model Training

The DataAugmentation class in …/data_augmentation.py handles image augmentation for enhancing YOLOv8 model training datasets. Key features include:

Read more

Data Augmentation Techniques
[Edit section]
[Copy link]

References: examples/YOLOv8_data_augmentation/data_augmentation.py

The DataAugmentation class in …/data_augmentation.py implements various image augmentation techniques to enhance the training dataset. Key features include:

Read more

Bounding Box Visualization
[Edit section]
[Copy link]

References: examples/YOLOv8_data_augmentation/visualise_bounding_boxes.py

• • •
Architecture Diagram for Bounding Box Visualization
Architecture Diagram for Bounding Box Visualization

The BoundingBoxVisualiser class in …/visualise_bounding_boxes.py provides functionality to visualize bounding boxes on augmented images. This tool is crucial for verifying the correctness of data augmentation processes. Key features include:

Read more

YOLOv8 Model Training
[Edit section]
[Copy link]

References: examples/YOLOv8_train/train.py

• • •
Architecture Diagram for YOLOv8 Model Training
Architecture Diagram for YOLOv8 Model Training

The YOLOModelHandler class in …/train.py manages YOLOv8 model operations:

Read more

API and Server Implementation
[Edit section]
[Copy link]

References: examples/YOLOv8_server_api, examples/user_management

• • •
Architecture Diagram for API and Server Implementation
Architecture Diagram for API and Server Implementation

The server-side API is implemented using Flask, with the main application logic in …/app.py. This file initializes the Flask application, configures JWT authentication, and registers blueprints for different functionalities.

Read more

Object Detection API
[Edit section]
[Copy link]

References: examples/YOLOv8_server_api/detection.py

• • •
Architecture Diagram for Object Detection API
Architecture Diagram for Object Detection API

The detection_blueprint Flask blueprint handles object detection requests. Key components include:

Read more

Label Processing
[Edit section]
[Copy link]

References: examples/YOLOv8_server_api/detection.py

• • •
Architecture Diagram for Label Processing
Architecture Diagram for Label Processing

The process_labels() function handles the processing of detection labels to remove overlapping and completely contained labels for specific categories, particularly "Hardhat" and "Safety Vest". This processing is crucial for improving the accuracy of object detection results. The main steps in label processing are:

Read more

Helper Functions
[Edit section]
[Copy link]

References: examples/YOLOv8_server_api/detection.py

• • •
Architecture Diagram for Helper Functions
Architecture Diagram for Helper Functions

Several helper functions in …/detection.py facilitate image processing, object detection, and result compilation:

Read more

User Management
[Edit section]
[Copy link]

References: examples/user_management

• • •
Architecture Diagram for User Management
Architecture Diagram for User Management

User management functionality is implemented in the …/user_management directory. The core components include:

Read more

Authentication
[Edit section]
[Copy link]

References: examples/YOLOv8_server_api/auth.py

• • •
Architecture Diagram for Authentication
Architecture Diagram for Authentication

The authentication process is implemented in the …/auth.py file. The create_token() function, mapped to the /token endpoint, handles the core authentication logic:

Read more

Database Configuration
[Edit section]
[Copy link]

References: examples/YOLOv8_server_api/app.py, examples/user_management/app.py

• • •
Architecture Diagram for Database Configuration
Architecture Diagram for Database Configuration

The database configuration is handled flexibly using environment variables and SQLAlchemy. In …/app.py, the database URI is set through the Config class, allowing for easy configuration changes. The db.init_app(app) call initializes the SQLAlchemy database with the Flask application.

Read more

Integration with Messaging Platforms
[Edit section]
[Copy link]

References: src, examples/line_chatbot

• • •
Architecture Diagram for Integration with Messaging Platforms
Architecture Diagram for Integration with Messaging Platforms

The system integrates with various messaging platforms through dedicated notifier classes:

Read more

Notifier Classes
[Edit section]
[Copy link]

References: src/notifiers

• • •
Architecture Diagram for Notifier Classes
Architecture Diagram for Notifier Classes

The …/notifiers directory contains classes for sending notifications through various messaging platforms. The __init__.py file imports and exposes these classes, making them easily accessible throughout the project.

Read more

Notification Sending
[Edit section]
[Copy link]

References: src/notifiers

• • •
Architecture Diagram for Notification Sending
Architecture Diagram for Notification Sending

The TelegramNotifier, LineNotifier, MessengerNotifier, WeChatNotifier, and BroadcastNotifier classes handle sending notifications through their respective platforms. Each notifier class provides a send_notification() method that accepts a message and an optional image.

Read more

LINE Chatbot Integration
[Edit section]
[Copy link]

References: examples/line_chatbot

• • •
Architecture Diagram for LINE Chatbot Integration
Architecture Diagram for LINE Chatbot Integration

The LINE chatbot integration is implemented in …/line_bot.py. The chatbot handles various types of messages and events:

Read more