## 5 Automated Processing Procedure  
The processing procedure can be seen in Figure 9 and will be introduced as follows. The system starts reading the thermal image of the camera, which is the input of the system. Once the image is read, the first step of the algorithm is to detect the surface of the panels. The purpose of this step is twofold. The first one is to make the algorithm more robust against abnormal elements or objects in the scene. The second one is to build a mask to be used in the next steps of the algorithm. An example that summarizes previous considerations can be seen in Figure 10.  
In Figure 10 left, it can be seen that the hottest regions of the image are located over the car. However, if the panel surface is detected, these thermal abnormalities can be properly eliminated. The perimeter of the surface of the panels is highlighted (in green), and it can also be seen as an image mask in the right part of the Figure. For the detection of the panels surface, the K-means clustering algorithm [26] is applied. More specifically, the thermal images are clustered into \(k\) groups (\(k=3\)) according to the pixel intensities. Pixels that belong to a given cluster will be more similar in intensity than pixels that belong to a separate cluster. In this case, one cluster corresponds to the pixels of the background, the other cluster corresponds to the pixels of the panels shadows, and the last cluster of interest corresponds to the pixels on the surface of the panels. It should be noted that the pixels that belong to the panels surface is the cluster with the highest intensity. Therefore, it can be automatically identified. Figure 9: Main steps of the automated thermal processing procedure. The second step of the algorithm is to perform the individual panel detection, which can be seen in Figure 11. Given the original image (first image in Figure 11), the algorithm tries to detect PV panels inside the mask (second image in Figure 11). In order to do so, the first step is to detect the contours of the PV panels (third image in Figure 11). The contours are obtained from the binary image after applying an adaptive thresholding technique [27]. Once the contours are obtained, the next step is to correct the perspective distortion [28] of all the detected contours. This procedure is done by calculating the best transformation matrix, which minimizes the error when correcting the perspective of all the contours in the image. The error is calculated taking into consideration the physical dimensions of a PV panel and calculating the difference (euclidean distance) between the four corners that define each contour and the four corners that define the PV panel. Therefore, this procedure is repeated as many times as the number of the detected contours in the thermal image. The transformation matrix with the lowest error is taken as the final transformation matrix and it is finally used to correct the perspective of all the contours (panels) in the image. It should the noted that, when the obtained error is too high, the image does not include panels. Therefore, this error can be used as a robust indicator to know whether the image contains PV panels or not. This step can be seen in Figure 9 referred as 'quality', and the result can be seen in the last image of Figure 11, where the border of the image is green, which means that the error is low, indicating that this step of the algorithm detected panels inside the mask. Additionally, it can be seen in Figure 11 that the algorithm detects and identifies nine individual panels (marked in green) and also identifies two more panels (red) that are not completely seen in the image. The perspective corrected PV panels can be seen in Figure 12. As commented before, this step is performed based on the real size of a PV panel. In this case, a PV panel has a size of \(2\times 1\) m.  
Figure 11: Individual panel detection and identification. Figure 10: Panels surface detection.