## 3 Method Implementation
### Digital Meter Reading
#### 3.4.1 Image Preprocessing  
Image preprocessing comprises three steps: Gaussian filtering, graying, and binarization. Gaussian filtering is mainly used to reduce noise in an image to make it smoother. Gaussian filtering primarily aims to reduce noise in an image, resulting in a smoother appearance. The principle involves scanning each pixel in the image using a Gaussian kernel, wherein the weighted average gray value of the pixels within the kernel is assigned as the value of the pixel point at the center of the kernel. The Gaussian filter determines the weights based on the shape of the Gaussian function, with the one-dimensional and two-dimensional Gaussian functions depicted as follows:  
\[f(x)=\frac{1}{2\pi\sigma_{x}\sigma_{y}}e^{-\frac{(x-x_{y})^{2}}{2\sigma_{x}^{2 }}-\frac{(y-x_{y})^{2}}{2\gamma y^{2}}} \tag{2}\]  
\(\sigma\) is the standard deviation, which controls the width of the Gaussian distribution, determining the level of blur. A larger \(\sigma\) results in a stronger blurring effect. \(x\) and \(y\) are the coordinates relative to the center of the filter. \(e\) denotes the exponential function. Graying preprocessing aims to diminish the influence of surrounding factors on the dial within the image, thereby reducing image complexity, emphasizing key information, and rendering the image more suitable for diverse image processing and analysis tasks. The goal of graying is to convert each pixel of a color image from the RGB space to the grayscale space. This entails weighting and averaging the three channel values (R, G, and B) of a color pixel to derive the corresponding grayscale value. The grayscale value for each pixel is calculated using the following function:  
\[\text{Gray}=0.299\times\text{R}+0.587\times\text{G}+0.114\times\text{B} \tag{3}\]  
R, G, and B are the red, green, and blue channel values of the pixel, respectively. The color image is converted to grayscale using the OpenCV library's cv2.cvtColor() function. The goal of binarization is to convert pixel values in a grayscale image to black and white for further segmentation of the target object and the background. Typically, a threshold is established based on the grayscale value of each pixel, where values exceeding the threshold are assigned white (255), while those equal to or below the threshold are assigned black (0). In this study, we employ an adaptive thresholding method for binarization, which determines the threshold value based on the local characteristics of the image. This approach is particularly suitable for scenarios with uneven lighting or complex backgrounds. Binarization is implemented by using OpenCV's cv2.adaptiveThreshold() function. Figure 15: Digital meter reading process. A closing-opening operation is performed on the corrected image, followed by drawing a contour image using contour detection to remove small areas. Subsequently, rectangles are detected, and the initial position of the dial is determined based on the area and aspect ratio of the rectangle. Both opening and closing operations consist of erosion and dilation. In opening operations, erosion is performed first, followed by dilation. The initial erosion can eliminate noise, isolated small components, and protrusions in larger structures within the image. Subsequent dilation can restore the original shape and structure of the target object, which may have shrunk due to erosion. Consequently, the opening operation effectively filters noise without significantly altering the shape of the target object's contour, resulting in smoother contours that facilitate target localization. The function can be expressed as follows:  
\[A\cdot B=(A\ominus B)\oplus B \tag{4}\]  
* \(A\) is the input image. * \(B\) is the structuring element (or kernel). * \(\ominus\) denotes erosion. * \(\oplus\) denotes dilation. * The opening operation first erodes the image to remove small objects or noise, and then dilates it to restore the size of the larger objects.