Skip to content

home‐yolo.py

Mathew edited this page Feb 20, 2024 · 1 revision

Home - home-yolo.py

The home-yolo.py script serves as the central command unit for the Automatic License Plate Recognition (ALPR) system, orchestrating the application's core functionalities, including the user interface (UI) initialization, video processing, plate detection, and interaction with the database for logging and resident management.

Key Features and Functions

Application Setup

  • Initializes the PySide6 main window and loads the UI from mainFinal.ui.
  • Configures button actions to start and stop video processing, and to navigate through resident and entry logs.

Video Processing

  • Utilizes two background threads (Worker1 and Worker2) for handling video capture and processing without blocking the UI.
  • Worker1 captures video frames, applies the YOLOv5 model to detect license plates, and crops the detected plates for further processing.
  • The cropped plates are then passed through another YOLOv5 model to recognize characters on the plates.

GUI Updates

  • Dynamically updates the main window with detected plates, character recognition results, and database queries regarding resident information and entry logs.
  • Implements functionalities for adding new residents, viewing resident details, and logging entry times and plate details.

Database Interaction

  • Interacts with the application's database to retrieve and update information related to recognized plates and associated residents.
  • Utilizes db_entries_time, dbGetAllEntries, db_get_plate_status, and db_get_plate_owner_name for database operations.

Utility Functions

  • Includes utility functions for device selection based on the availability of CUDA or MPS, ensuring optimal model performance.
  • Implements image processing functions such as cropping detected plates and formatting the recognized plate text for standardization and readability.

Error Handling and Resource Management

  • Catches and suppresses warnings related to user warnings.
  • Manages system resources effectively, including garbage collection and clearing CUDA cache to ensure smooth operation.

Technical Workflow

  1. Initialization: On application launch, MainWindow is instantiated, setting up the GUI and connecting actions to their respective slots.
  2. Video Processing Start: Upon user interaction, Worker1 starts capturing and processing video frames in a separate thread.
  3. Plate Detection: Frames are processed using a pre-trained YOLOv5 model to detect license plates.
  4. Character Recognition: Detected plates are further processed to recognize characters using another YOLOv5 model.
  5. Database Queries: Recognized plate numbers are used to query the database for related resident information and entry logs.
  6. GUI Updates: The main window is updated in real-time with the processed information for user interaction.
  7. Resource Management: Ensures efficient use of resources and clean-up on application closure.

Conclusion

home-yolo.py embodies the core logic and workflow of the ALPR system, integrating deep learning models with a user-friendly interface for real-time license plate recognition and management. Through a combination of PySide6 for the UI, PyTorch for deep learning inference, and efficient resource management, it provides a robust solution for automatic license plate detection and recognition.