Automatic Rain Detection System Based on Digital Images of CCTV Cameras Using Convolutional Neural Network Method

The Meteorology, Climatology and Geophysics Agency (BMKG) has a duty to provide weather information including rainfall. BMKG has several types of rainfall gauges, but these are not evenly distributed across regions. The solution to increase the density of rainfall observations is to use existing sources to obtain weather information. This research uses Closed Circuit Television (CCTV) that is spread across the Jakarta area to produce information on rainy conditions. The method used is the Convolutional Neural Network (CNN). The image from CCTV will be used for the training and testing process, so as to get the best accuracy model. The results of this model will be used for rain detection on CCTV digital images. The rain detection process is carried out automatically and in real time. The results of the rain detection process will be displayed on the map according to the location where the CCTV was installed. This research has succeeded in making a CNN model for rain detection with a training accuracy of 98.8% and a testing accuracy of 96.4%, as well as evaluating the BMKG observation data, so it has an evaluation accuracy of 96.7%.


Introduction
Rainfall is the amount of rain that falls in a location over a period of time [1]. The Meteorology, Climatology and Geophysics Agency (BMKG) conducts rainfall observations with several equipment which are OBS rain gauge, hellman rain gauge, automatic rain gauge and automatic weather station [2].
The increase in the number of rainfall monitoring equipment each year does not match the increasing need for weather information. This research intends to increase the number of rain observation locations by utilizing equipment owned by micro-cellular pole companies in the DKI Jakarta area, so its not burdening the BMKG budget. One of the tools that can be used to obtain rain information comes from digital images recorded by CCTV cameras [3]. The rain that occurs can be caught by CCTV cameras are widely scattered in the Jakarta area. There are more than 4000 CCTV cameras installed in Jakarta. The number of CCTVs installed in the Jakarta area is very large when compared to the rain observation equipment owned by BMKG. The use of CCTV cameras to obtain rain information is expected to increase the density of rain observations owned by BMKG. So that the weather information submitted by BMKG will be faster, on time and accurate.
This research uses CNN to detect rain in digital images [4]. The process is carried out for rain detection by collecting digital CCTV image data from 20 locations in the Jakarta area. The collected digital images are 4000 digital images. The data will be divided into three of categories, it is training data, validation data and testing data. Training data and validation data are used for the training process to produce a CNN model. To produce a model with the best accuracy, several training processes are The system is designed to download digital CCTV images from the internet and perform the rain detection process automatically and in real time. The classification results are displayed on the map according to the location of the CCTV installed.

Research Methodology
The CNN model design stage begins with the selection of sample data used as input for training data, validation and testing [4]. The sample data used in this research are digital CCTV camera image data from 20 locations in the DKI Jakarta Province. Figure 1 shows the CCTV locations scattered in the Jakarta area marked with a purple dot. The grid is carried out on the CCTV location map in the Jakarta area. Each grid is represented by one CCTV unit installed so that 20 CCTV locations are operated. Used camera on the installed CCTV already has Full HD resolution, it is 1920 x 1080 pixels so the image produced by CCTV is good for rain classification on digital images. CCTV data can be accessed by the public is downloaded automatically. The data that has been collected as many as 4000 images will be separated between digital images showing rainy conditions and dry conditions. An example of a digital image from CCTV can be seen in figure 2 and figure 3.  The data that has been collected will be separated into 70% training data, 20% validation data and 10% test data from all the data that has been collected. The training process is carried out by applying the CNN structure that has been designed on the training data and validation data. The predetermined parameters are processed using the Python programming language, tensorflow framework and keras backend, to process training data and validation data so that the model is obtained and the training accuracy of the model is known. If the model shows a good accuracy value, then it will be used to test the test data so that the classification of the test data can be found. Layer visualization was performed in the CNN modeling process to see how each layer on CNN worked. Visualization of the training process at each layer is done by projecting the activation feature back to the beginning of the training process. The layer visualization in the training process is shown in figure 4. The CNN architecture for this research contains few layers and parameters. The input layer is a digital image data that will be used for the training and testing process. The convolution layer is a major part of the CNN architecture. This layer uses filters that contain weights to detect characters from objects such as colors, curves or edges. ReLU (Rectification Linear Unit) has a function to change the output value to 0 if the input is negative. Max Pooling layer aims to reduce the size of an image by making the grid match the specified matrix size and taking the maximum value from the grid. Fully connected layer gets input from the previous process to determine which features are most correlated with a particular class. The function of this layer is to unite all nodes into one dimension [5].
The daily output of the training process is a model with high accuracy. The model will be used to test the prepared test data. The output of the testing process is the classification of digital images that have rain or dry information. The step taken for testing is to call the model that has been stored for processing with digital image test data, so that it can provide output in the form of rain detection.
This research intends to create a rain detection system on CCTV digital images that can be done automatically and in real time with a processing time interval of one minute. Created system process can be seen in the block diagram in figure 5.  Rain detection system is run automatically with several stages. The first process is the process of crawling digital image data sourced from the internet. The crawling process on a system built using the PHP programming language. CCTV data that has been downloaded using the crawling process is one image frame data that has a video format. To carry out the rain detection process on a digital CCTV camera image, the data needs to be converted into an image format. This conversion process uses the python programming language. Data that has an image format will be saved into the real time data folder. The prediction function in this system is a process for detecting rain conditions on a digital CCTV camera image using a model with the best performance created in the training process. This process uses the python programming language, tensorflow framework and keras backend. Rain detection results are information of rain or dry which will be stored in the rain detection results database. The final result of the system is a map display that shows rainy or dry conditions at each CCTV location. To create this map, the Leaflet.js library and the PHP programming language were used. To retrieve data from the database, a connection between MySQL and PHP is required.

Experimental Result and Discussions
This research has two main processes, the first is designing the CNN model to get the best accuracy in detecting rain on the digital CCTV camera image. The second process creates a system for detecting rain based on the model created, and displays it on a map.
Determination of the best parameters is done by a try and error process. Training was carried out several times with different parameters to get the best accuracy model. The parameters referred to are the effect of the number of epochs, the effect of the image input size, the effect of the kernel size and the effect of the learning rate. The purpose of determining the parameters of this model is to get the best model by paying attention to the parameter values.
To get the best model for rain detection on CCTV digital images, several steps are needed. The first process determines the CNN parameters used for the training process. The model created is then used by the prediction function to detect rain from the prepared test data. This process is called the testing process. From the testing process, the testing accuracy value of the model is obtained. The model used in this research is the model that has the best accuracy in the training process and in the testing process. If the model that is made does not have good performance, the process will start from the beginning by determining CNN parameters and continue with the training and testing process until you get the best performance model. The results of the training process can be seen in table 1. From the six training processes, it can be seen that the best accuracy is in the sixth training process with an accuracy of 98.8%. The results of the training process one to six show fluctuating accuracy results. The parameter values greatly affect the accuracy of the training process. To find out the performance of the model through the prediction process, a testing process is carried out. The results of the accuracy of the model testing process can be seen in table 2.  The results of model testing show varied results. From the test results, it is known that the accuracy of the sixth model in the testing process is 96.4%. The sixth model has the best performance in rain detection on digital CCTV camera images. This model will be used by an automatic rain detection system that is designed.
The model with the best accuracy is made in the training process, which will be used for the prediction process of rain conditions. The system performs the prediction process automatically and realtime then displays the results on a map. Rainy conditions maps can be accessed via a web browser. The results of displaying rain conditions on the map can be seen in figure 6. There needs to be a validation process for a system that has successfully detected rain on a digital CCTV camera image. Validation is done by comparing the results of automatic rain detection from the system that has been made, and rain measurement data from the BMKG. There are 20 locations for automatic rain detection, but not all locations can be compared with BMKG observation data. Based on the distance to the location of automatic rain detection on CCTV cameras, BMKG rain observation locations and data availability, there are three locations that can be validated. The system is made to provide rain detection output with rain and dry categories. When the BMKG equipment detects rainfall   Table 3 shows the comparison results of rain detection which shows that the system that has been made is good at detecting rain. The validation has shown the accuracy of the rain prediction system is 96.7%. This system is very good if applied to increase the density of BMKG rain observations.

Conclusions
The rain detection method in digital images using a convolutional neural network is very reliable to use. CNN has a high performance to be used in this research. The accuracy results of the model show that the best performance obtained using CNN has a training accuracy of 98.8% and a testing accuracy of 96.4%. An evaluation of the rain detection system has been carried out on the results of BMKG observations and an accuracy of 96.7% has been obtained. These results indicate that the selected parameters are appropriate, so the model has the best performance.
The automatic and real time rain detection system has been running well, starting from the crawling process, converting video to image, prediction function, database and map display. This research has succeeded in establishing a connection between each process using a different programming language. The final result of the system can be displayed on a map for the benefit of the user.