Architecture๏ƒ

MIRA is built with a modular asynchronous architecture using Python and PyQt5. This design ensures that the user interface remains responsive even during heavy YOLO inference or high-resolution video capture.

๐Ÿ“‚ Project Structure
mira/
โ”œโ”€โ”€ main.py                    # Application entry point & theme detection
โ”œโ”€โ”€ main_window.py             # Main UI controller (Signal/Slot coordination)
โ”œโ”€โ”€ camera_worker.py           # Multi-threaded camera management
โ”œโ”€โ”€ camera_config_manager.py   # Camera profiles (save/load/default)
โ”œโ”€โ”€ detection_engine.py        # AI logic (YOLO inference & tracking)
โ”œโ”€โ”€ data_manager.py            # Data persistence & Excel generation
โ”œโ”€โ”€ widgets.py                 # Reusable custom UI components
โ”œโ”€โ”€ style_dark.qss             # Dark theme stylesheet
โ”œโ”€โ”€ style_light.qss            # Light theme stylesheet
โ””โ”€โ”€ trackers/                  # Tracker configs (BotSORT/ByteTrack)

โ€”

Core Components๏ƒ

Main UI Logic (main_window.py)

๐ŸŽฎ CameraController

Acts as the orchestrator of the application. It handles user interactions, manages the state of the UI, and routes signals between the camera thread and the detection engine.

Async Processing (camera_worker.py)

๐Ÿ“น CameraThread

Runs in a dedicated thread to prevent UI freezing. It handles the OpenCV video stream, applies real-time image adjustments (gain, zoom), and emits frames for display.

AI Inference (detection_engine.py)

๐Ÿง  DetectionEngine

Wraps the Ultralytics YOLO model. It performs object detection, calculates surface areas, and applies temporal averaging algorithms to ensure count stability.

Data & Export (data_manager.py)

๐Ÿ’พ DataManager

Responsible for organizing images into the directory structure and generating the multi-sheet Excel reports using Pandas and OpenPyXL.

โ€”

Custom UI Elements๏ƒ

MIRA features several specialized widgets built from scratch to meet microscopy needs:

Widget Name

Purpose

ChamberRectItem

Interactive graphical representation of Malassez/KOVA grids.

MySwitch

A modern animated toggle switch for Detection and Camera states.

DictViewer

Real-time table display for class-wise detection counts.

LogHandler

Themed logging console with color-coded severity levels.

โ€”

๐Ÿ”„ Signal-Based Communication

MIRA relies heavily on the PyQt Signal/Slot mechanism. For example, when the CameraThread captures a new frame, it emits a signal that the DetectionEngine receives to perform analysis, which then signals the MainWindow to update the display. This decoupled design makes the code easier to maintain and extend.