DOI: 10.5281/zenodo.16890496
title: Software and dataset of Fusion of electrical and optical methods in the detection of partial discharges in dielectric oils using YOLOv8

description: # Software and Dataset of Fusion of Electrical and Optical Methods in the Detection of Partial Discharges in Dielectric Oils using YOLOv8

*By José Miguel Monzón-Verona, Santiago García-Alonso, and Francisco Jorge Santana-Martín*

## Abstract

This document provides a comprehensive guide to the software and datasets contained in this repository. These resources were developed for the research presented in the article: *"[Article Title Fusion of Electrical and Optical Methods in the Detection of Partial Discharges in Dielectric Oils using YOLOv8]"doi: 10.20944/preprints202509.0331.v1*. The repository includes the necessary code and data to reproduce the training and inference analysis of a YOLOv8-based Convolutional Neural Network (CNN) for detecting and quantifying Partial Discharges (PD).

---

## Table of Contents1.  [Overview](#overview)2.  [Repository Structure](#repository-structure)3.  [System 1: Video Analysis and OCR for PD Quantification](#system-1-video-analysis-and-ocr-for-pd-quantification)    *   [Phase 1: Setup and Initialization](#phase-1-setup-and-initialization)    *   [Phase 2: Frame-by-Frame Processing (Main Loop)](#phase-2-frame-by-frame-processing-main-loop)    *   [Phase 3: Finalization](#phase-3-finalization)4.  [System 2: Semi-Automatic Dataset Generation for HQ Videos](#system-2-semi-automatic-dataset-generation-for-hq-videos)    *   [Phase 1: Setup and Loading](#phase-1-setup-and-loading)    *   [Phase 2: Video Processing Loop](#phase-2-video-processing-loop)    *   [Phase 3: YOLOv8 Dataset Generation](#phase-3-yolov8-dataset-generation)5.  [How to Cite](#how-to-cite)

---

## Overview

This repository contains two primary components, each corresponding to a different data acquisition method:

1.  **DDX Electrical Detector Data:** This includes the software and a manually generated dataset for analyzing images from the DDX electrical detector.2.  **High-Quality (HQ) Camera Data:** This includes the software for semi-automatic dataset generation and the resulting dataset from a high-resolution camera.

The training and inference processes for the YOLOv8 model are detailed below. The model was trained for over 150 epochs using the partitioned datasets described herein.

## Repository Structure

The repository is organized into the following main directories:/|-- Software_dataset_for_DDX/| |-- dataset/ # Images and labels for DDX| |-- software/ # Python scripts for inference and OCR| -- models/ # Trained YOLOv8 model for DDX data | |-- Software_dataset_for_HQ/ | |-- dataset/ # Images and labels for HQ camera | |-- software/ # Python script for semi-automatic dataset generation | -- models/ # Trained YOLOv8 model for HQ data

## System 1: Video Analysis and OCR for PD Quantification

This system is designed to process video streams (primarily from the DDX detector), perform object detection using YOLOv8 to identify relevant indicators, and use Optical Character Recognition (OCR) to extract quantitative data. The process is divided into three main phases, as illustrated in Figure 1.

![Flowchart of the Video Detection and OCR System](flowchart_video_ocr_system.png)_Figure 1: Flowchart of the Video Detection and OCR System._

### Phase 1: Setup and Initialization

This preliminary phase prepares all necessary components for the analysis. It performs three sequential tasks:1.  **Startup and Configuration:** The process begins by loading user-defined configurations, such as the input video path, YOLOv8 model path, confidence thresholds, and a list of target classes that will trigger OCR (e.g., `pd_level_value`, `voltage_value`, `attenuation_value`).2.  **Engine Loading:** The two main inference engines—the YOLOv8 object detection model and the Python EasyOCR engine—are initialized and loaded into memory. This is performed only once at startup to optimize performance. The number of available GPUs is also determined.3.  **File Handling:** The input video stream is opened, and output files are created. This includes a new video file for visual annotations and a text file to log detailed detection data.

### Phase 2: Frame-by-Frame Processing (Main Loop)

This is the operational core of the system, where each frame of the video is analyzed sequentially.1.  **YOLOv8 Inference:** The current frame is fed into the YOLOv8 model, which identifies and locates all objects of interest that exceed the predefined confidence threshold, returning their bounding boxes, class labels, and confidence scores.2.  **Detection Loop:** The system iterates through each detection found in the frame.3.  **OCR Target Class Check:** For each detection, a decision is made based on its class label. If the class is predefined as an OCR target, the system proceeds with OCR inference.4.  **OCR Inference:** This critical step extracts quantitative data:    *   a. **ROI Cropping:** The exact portion of the image contained within the detection's bounding box is extracted from the frame.    *   b. **OCR Application:** The EasyOCR engine analyzes this small Region of Interest (ROI) to recognize the textual information present.    *   c. **Value Interpretation:** The extracted text is processed and converted into a numerical value.5.  **Output Logging:** All detection data is logged. Bounding boxes and corresponding labels (including confidence scores and OCR values, if applicable) are drawn on the output video frame. Detailed information about each detection is appended as a new line to the output text file.

### Phase 3: Finalization

Once all frames have been processed, the system performs an orderly shutdown, closing all files and releasing system resources, leaving the output files ready for further analysis.

## System 2: Semi-Automatic Dataset Generation for HQ Videos

To train the YOLOv8 model for PD detection in videos from the High-Quality (HQ) camera, a Python script was developed to automate the generation of a labeled dataset. This process identifies candidate events, filters out known false positives, and generates a structured dataset in the format required by YOLOv8. The methodology is based on background subtraction, contour analysis, and a manual spatial exclusion filter. The process is summarized in Figure 2.

![Flowchart of the Semi-Automatic Dataset Generation Process](flowchart_dataset_generation.png)_Figure 2: Flowchart of the Semi-Automatic Dataset Generation Process._

### Phase 1: Setup and Loading

In this initial phase, all resources are prepared. The script reads the video file path and allows the user to manually define spatial exclusion zones on the first frame. These zones are key to filtering out known, stationary sources of noise or light reflections.

### Phase 2: Video Processing Loop

This is the core of the script, operating on a frame-by-frame basis.1.  **2a. PD Detection and Filtering:** This block encapsulates the computer vision logic. It subtracts the background to identify changes, binarizes the resulting image, and finds contours corresponding to potential PD events. It then applies two filters: a minimum area filter to discard small noise and the user-defined exclusion zones filter.2.  **2b. Temporary Storage:** If a frame contains at least one valid PD event that has passed all filters, the script saves the original frame as an image and temporarily stores the coordinates of the corresponding bounding boxes.

### Phase 3: YOLOv8 Dataset Generation

Once the entire video has been analyzed, this final phase takes all the collected data and organizes it into the folder structure and file formats required by YOLOv8. This includes:*   Splitting the collected images and labels into training, validation, and test sets.*   Normalizing the bounding box coordinates.*   Creating the `.yaml` configuration file required to train the YOLOv8 model.

## How to Cite

If you use this software or dataset in your research, please cite our paper:

> *[José Miguel Monzón-Verona, Santiago García-Alonso, and Francisco Jorge Santana-Martín]. [2025]. "[Fusion of Electrical and Optical Methods in the Detection of Partial Discharges in Dielectric Oils using YOLOv8]". [Journal Electronics]. [DOI:]*