COVID-19 has wreaked havoc around the world and the spread of COVID-19 has not been curbed totally by June, 2020. According to the situation report of the WHO, there have been 9,653,048 confirmed cases and 491,128 deaths by 27 June 2020 [1] . Recently, many researchers have developed a variety of detection methods of COVID-19, such as reverse transcription-polymerase chain reaction (RT-PCR) technology [2, 3] , X-ray [4] and chest CT imaging [5] . In addition to the need for breakthroughs in testing techniques, SARS-CoV-2 must be controlled at source to prevent a sustaining surge in COVID-19 confirmed and death cases. Small respiratory droplets can transmit SARS-CoV-2, which is known to be transmissible from presymptomatic and asymptomatic individuals [6] . One thing to reduce virus's spreading is wearing masks in public [6] . Advice on using face masks proposed by the WHO [7] , analysis [6] and researches [8] have supported that wearing masks can prevent the spread of potential viruses during pandemic. An evidence research even thinks that wearing masks in public is a symbol of social solidarity among the response to the worldwide pandemic [9] . The WHO recommends that the surgical face masks used by health workers should be discarded once used and during severe shortages the extended use of faces masks can be considered [10] . Because face masks only work when being worn within their periods of validity. On the other hand, more often in daily life, the majority of people wear surgical face masks in short-time but high-frequent way and in low-risk or middle-risk environment. The face masks may be used twice or three times, even four or five times if in relatively safe environment and maintained properly, which is reasonable and common especially under the condition where face masks are in shortage.
In this case, there is no doubt that the service life of masks depends on the use methods, use intensity, environmental condition and the material of masks, etc. In daily life, it often happens that common people forget the service stage of the current mask after having used it in the high-frequent but short-time way. Meanwhile, the service life of face masks decreases differently after being used in different conditions. As a result, the masks' remaining time of effective protection varies. With those faces masks whose use time are unknown, continuing to use them may lead to poor protection and other unexpected incidents; discarding them directly is an inappropriate behavior. It is a waste of face masks, especially in the case that masks are in shortage during the epidemic. It is necessary to detect the service stage of our face masks, but there are few researches on the service stage of face masks. Therefore, we aim at studying what service stage the face mask is in, which may play a positive role in protecting the uninfected people and reducing the spread of virus.
According to Javid et al., wearing a mask in public may become our unified action in the fight against COVID-19 [11] . Due to the short service life and worldwide use of masks, it is not practical for masks to adopt special machines to centralized detection. Hence, it is urgently needed to develop an easy-to-operate, portable testing device for detecting anytime and anywhere. Therefore, in this research, we propose a portable mask service stage detection system based on mobile phone. Its work procedures are as follows: 1) users first take a micro-photo of the mask being used with a mobile microscope; 2) then the micro-graph of the mask is uploaded in the WeChat Applet; 3) the result of back-end detection eventually can be obtained through WeChat Applet. This detection device is simple, easy to operate and effective.
In the common fight, the ordinary people often wear surgical masks while N95 masks are only recommended for healthcare workers or professionals at high risk of coming into contact with patients [12] . Radonovic et al. analyzed the data which came from 7 health care delivery systems and 4 seasons of peak viral respiratory illness, and found that in this trial, wearing N95 respirators and wearing medical masks resulted in no significant difference in the incidence of laboratoryconfirmed influenza [13] . Additionally, the research suggests that N95 respirators should not be recommended for the general public, namely, those not in close contact with influenza or suspected patients [12] . Using N95 respirators may lead to discomfort, like headaches [14] . Even a previous study [15] has reported that there is an inverse relationship between the level of wearing N95 respirators and the risk of clinical respiratory illness. Therefore, we choose surgical mask as the research object, which is the most widely used. It makes experimental data more scientific and ultimately our detection system can benefit more people to the greatest extent. In this study, after obtaining the micro-graphs of masks at different wearing periods, the texture features of the photos are analyzed.
Methods of texture analysis include fractal analysis, Fourier transformation and the gray level co-occurrence matrix (GLCM) [16] . Haralick et al. reported that the GLCM was a method to quantify the spatial relationship between adjacent pixels in an image [17] . GLCM is widely used in disease detection [18, 19] , skin texture analysis [20] , and defect detection [21] , etc. Given the above, GLCM is feasible and efficient in image texture feature analysis. Therefore, we choose GLCM to analyze the texture features of masks.
Due to K Nearest Neighbor (KNN) method's simple implementation and distinguished performance in classification tasks [22] , it is widely employed in text categorization [23, 24] , medical domain [25] , eating patterns exploration [26] , leaf disease identification [27] , indoor localization [28] , etc. Hamed et al. compared the performance of KNN variant (KNNV) algorithm (which derived from KNN) and other three algorithms in the classification of COVID-19 patients, and found that KNNV algorithm could classify COVID-19 patients more efficiently and accurately [25] . On the basis of the texture features extracted from the micro-photos taken in different period time, this paper employs KNN algorithm to establish the classfiers for detecting the use time of mask.
In this paper, we propose a portable face mask service stage detection system, which is easy to operate and can work anytime and anywhere. It is based on the texture features of face masks and ground-truth of mask service stage data. To further quantify the differences of masks in different periods, the method of texture analysis is introduced. After extracting texture features from the micro-photos of face masks in different use periods, KNN algorithm is performed to detect which service period the face mask belongs to. The testing data are afterward used to validate the effectiveness of the proposed system.
The main contributions of this paper are threefold. First, we combine the texture features of face masks' micro-photos and their corresponding service stages based on the method of texture analysis. Based on GLCM, the texture features are successfully extracted from micro-photos obtained by high magnification lens attached to the mobile phone. Subsequently, we propose a detection method to judge the service stage of face masks with a KNN algorithm. Finally, based on the two contributions mentioned above, we have implemented a detection Wechat Applet for face masks using the data collected from three persons' wearing face masks in daily life, which may contribute to protecting the uninfected people and reducing the spread of virus.
A brief introduction to the proposed face mask service stage detection method is shown below. We initially use the portable and delicate mobile microscope device to get the micro-photos of face masks. After obtaining the picture, the first step is to extract texture features data from it. During the extraction process, we use GLCM to capture the contrast, energy, correlation, and homogeneity of the object face mask. Subsequently, KNN algorithm is employed to propose a classification model with the input texture features and the corresponding ground-truth use time. Eventually, we package the system into a library function in Matlab and embed it to the Wechat Applet we develop. This has been proved effective by similar previous researches [29, 30] . Fig. 1 . The overview of the portable detection device's "Hardware". The "Hardware" is composed of a mobile microscope, a phone with available system camera, etc. Specifically, a) and b) represent the mobile microscope and system camera, respectively; and c) shows the final removable device mainly assembled by a) and b). While the device is on work, the flash must meet the condition that the flash is always "on" to provide enough light. Fig. 1 displays the hardware configuration of the detection device: a mobile microphone (TIPSCOPE, Convergence(Wuhan) Technology Ltd., China), a phone with available system camera, etc. The detachable mobile microphone, which is the key to the hardware, is particularly chosen to display the details of face masks viz. ash particle, droplets or other debris more explicitly. It should be noted that the maximum magnification can reach 400x if the system camera and mobile microscope work together. In this research, we use system camera without magnification to get more scope of face masks. Fig. 2 shows how to collect the experimental data. To ensure the validity of the collected data, we photograph three inside locations of the face mask each time: left location (about one-third of the face mask and close to the left), middle location (about two-thirds of face mask), right (about one-third of the face mask and close to the right), as shown in Fig. 3 . In order to contain more usage scenarios, the face masks are worn in different conditions. Meanwhile, the flash of the phone's camera should be always "on" to provide enough light. We collect the images of a face mask used from day zero (new) to day five. Based on the conditions mentioned above, three images are immediately photographed after the face mask has been used for an arbitrary hour of the daytime.
Texture can be used to characterize the tonal or gray-level variations in an image [31] . The gray level co-occurrence matrix (GLCM) is chosen to disclose the texture features hiding in the face masks. GLCM is a second-order statistical method which calculates the frequency of pixel pairs with the same gray-level in an image and uses additional knowledge obtained from spatial pixel relations [32] . The co-occurrence matrix uses edge information to embed the distribution of gray-scale transformation [33] . Owing to the fact that much of the information required is embedded in GLCM, it emerges as a simple but effective technique.
14 measures of textural features are proposed by Haralick et al., and some of these measures are related to specific textural characteristics of the image [17] . In our study, we choose contrast, correlation, energy and homogeneity as measures. Specifically, contrast refers to the drastic change in gray level between adjacent pixels. High contrast images own high spatial frequencies. Correlation represents the linear correlation in an image. The higher the correlation value, the more linear the gray-scale relationship between adjacent pixel pairs. Energy stands for texture uniformity or pixel pair repetitions. High energy is produced when the distribution of gray level values is constant or periodic. Homogeneity is sensitive to the existence of near diagonal elements in a GLCM, indicating the similarity of adjacent pixels in gray scale.
With the increase of the use times, the wear of the mask causes a change in micro-structure of the mask's some parts, which leads to the difference between the worn-out parts and the unworn parts. Thus, the images in different the mask's service stage may perform variously in correlation and energy. Meanwhile, due to humans' respiration, cough and other respiratory related activities, more and more small particles impurities and droplets will adhere to the inside surface to the face mask. They probably result in the difference in the four measures mentioned above, among the images of different service stages.
Every element in GLCM contains second-order statistics, probability values for changes between gray levels i and j for a particular displacement d and angle θ, labeled as p(i, j) (normalized) [34] . Let M be the number of gray levels in the image, thus, the size of GLCM is M × M . In this research, we set M as 8. Subsequently, the measures are calculated as
where µ is the mean of GLCM while σ 2 stands for the variance of GLCM.
Considering that this task is relatively simple, so the model can be constructed with a relatively simple pattern recognition method. At the same time, in view of the deployment to the mobile phone terminal, the established model should be easy to deploy to the mobile phone terminal and convenient to maintain later. Compared with other algorithms, due to its simple implementation and significant classification performance, KNN is a very popular method in statistics and ranks top ten data mining algorithms [35, 36, 37, 38] .
KNN algorithm is different from model-based methods which first use training samples to build a model, and then predict the test samples through the learned model [39, 40, 41] . No training phase is required for the model-free KNN method. Instead, it conducts classification tasks obeying the following procedures: first, training samples are attached labels; next, the distance is calculated between the test sample and the training samples in each label; subsequently, after comparing the distances and obtaining the test's nearest neighbors, the serial number is obtained; finally, classification is generated, as shown in Fig. 4 . The distance is computed as:
where the n stands for the number of labels.
The main task in our research is to train the optimal k value after carrying out KNN classification successfully according to the efficiency of the classification performance.
After optimizing the system, the system is embedded to the Wechat Applet we have developed. To enrich our experimental data, we enlarge the data collection time from the first day to the fifth day (about an hour used time each day). It is generally recommended to replace the surgical mask every four hours. If the face mask is used for a long time, the large particles will be blocked on the mask surface or the ultrafine particles will be blocked in the pores of the mask filter material, resulting in the decrease of filtration efficiency and the increase of respiratory resistance [42] . According to the detection time, the detection results are within three categories viz. type I: normal use (day 0 to 1 viz. the face masks can be used securely), type II: early warning (day 2 to 3 viz. the face masks can be used safely, but it is close to the end of its service life) and type III: not recommended (day 4 to 5 viz. the face mask can be used in shortage, but it is better to change a new one). We choose the 'day' as unit based on the fact that we use face masks in high-frequent but short-time way and ordinary people hardly use face masks for 4 hours continuously. Additionally, on basis of using the same face mask several times, we classify the face masks belonging to day 4 and day 5 the type 'not recommended' to counterbalance the increase in use times. Fig. 5 reveals the workflow of the detection. After we have obtained the micro-photo of the face mask with mobile microscope and registered an account in the Wechat Applet, the micro-image is uploaded to the back-end of the system. Accordingly, the detection result will be sent in the message from the back-end.
To verify the efficiency of the detection system, macromeasures viz. macro precision, macro recall, and macro 1) Confusion matrix: we assume that "Positive" means the positive samples and "Negative" means the negative samples. Meanwhile, "True" represents that the prediction is right while "False" represents that the prediction is wrong. As a result, "TP" and "TN" mean that the positive sample is classified as "Positive" and the negative sample is labeled as "Negative", respectively. "FP" and "FN" represent that the negative sample is labeled as "Positive" and the positive sample is classified as "False". The four indicators make up the confusion matrix.
2) Precision: precision is only used to evaluated the classification ability of the positive samples within the range from 0 to 1. It is obvious that the larger precision is, the more effective the system is. It is computed by:
3) Recall: it is a ratio from 0 to 1. Obviously, the more it is close to 1, the better the system is. The calculation equation is:
4) F 1 : it is a harmonic mean of recall and precision. In this study, we consider the weight of recall and precision the same, which means attaching the weight of 0.5 to either of them. It is calculated by:
7) Macro-measures: metrics are calculated for each label, and then the weighted means are produced (normally the weight is the same except that the number of the samples in each label varies greatly).
Recall i (10)
where n means the total number of labels, and the M acro F 1i is F 1 of every label calculated by Equation 8.
In this study, we have collected 87 micro-images (excluding the invalid data) of surgical masks via the mobile microscope. The life span of face masks have little relationship with different people but much with the condition of use environment. Meanwhile, people's doing when wearing face masks also influences the life span of face masks. As a result, the data cover the conditions: speaking frequently, talking with others, running, shopping in supermarkets, shopping in vegetable markets, riding and wandering, etc. Every time three micro-photos (the left, the middle and the right) are photographed, they are initially averaged to eliminate existing disturbance, and then one final training sample is produced. As a result, after extracting texture features, 29 sets of training samples are obtained. The original 87 micro-images are used to carry out validation experiments. The evaluation indicators mentioned above are elaborated as the follows. 5 . The workflow chart of the face mask detection system. a) stands for collecting the micro-image of the face mask being used. b) with its branches b1), b2) and b3) means registering an account used to receive the detection result and the following uploading task. c) is the result sent by the Wechat Applet from the back-end. (The face mask used in the sample is in its service life of type I: normal use.)
To figure out the detailed information about the classification of the use time, we plot the confusion matrix of the three types as demonstrated in Fig. 6 . As can be seen from the results, 71 samples among 87 samples are predicted correctly, which suggests the model performs relatively well on the whole. According to the equations of macro-measures, we can easily see that macro-measures are convincing and scientific.
The macro-precision of the system reaches 82.87%±8.50%, which proves the efficiency of the detection system.
As mentioned above, we specially aim at obtaining the optimal k to get the most effective detection system. In KNN algorithm, K plays a key role in the performance of system. In other words, if the K factor is too small, there may exist the following problems: 1) the phenomenon of over fitting; 2) being easy to influenced by outliers; and 3) the system is too complex. While the K factor is too large, there may appear the elaborated problems: 1) the phenomenon of under fitting; 2) the system is constrained by the sample equilibrium; and 3) the system is too simple.
Hence, in this study, we analyze the correctly classified samples' number and accuracy under the condition that K's values vary from 4 to 16, as demonstrated in Fig. 7 . Accordingly, we can find the optimal-k-value is 6, with the the number TP 71 and the precision 82.87%. Additionally, K going from 4 to 6, the curve is roughly go up. For K ranging from 6 to 16, there are two stages in the descent tendency of the curve. First, the curve declines rapidly when K is from 6 to 9. Then it oscillates downward from 9 to 15, and the performance of system descends sharply when the K is changed to 16. The phenomenon referred above conforms to the theoretic prediction. Surprisingly, it is exactly consistent with the conclusion that the fixed optimal-k-value for all test samples should be k = √ n (where n > 100 and n is the number of training samples proposed by Lall and Sharma [43] .
we analyze the measures of all samples to inquire the tendency of modeling measures over time changes. Fig. 8 displays the micro-photos and their corresponding GLCMs' measures of three different service stages viz. 'normal use' stage, 'early warning' stage and 'not recommended' stage. As we can see from the micro-photos, when the use time increases, the mask becomes more and more dirty and there are many impurities and small droplets in the holes of the mask. It proves the accuracy of the analysis mentioned above that the protection becomes less effective over time. The curves reveal the variation tendency of the measures. Specifically, contrast and correlation increase while energy and homogeneity decrease over time. It should be noted that this rule can't be applied to all data, since the detection result is determined by composite force of the four measures. As a result, Fig. 7 . The influence of K factor on the performance of system. The Y axis on the right stands for the number of correctly predicted samples, and the Y axis on the left shows the corresponding accuracy. Intuitively, it can be seen that the optimal K is 6.
there exists the situation that some data don't obey the rule.
To validate the necessity of microscope, we record the results of using the original photo and micro-photo, which are shown in Fig. 9 . The two photos represent the same location of the face mask and belong to the type 'not recommended'. In Fig.  9 , we can see many details, such as droplets in the holes, etc. Meanwhile, we can see no details in the original photo except the obvious stain. It can be inferred that we will tell little difference if there is no stain or other obvious dirt. The detection result of the micro-photo is 'not recommended' while the original photo 's result is 'normal use', which verifies the indispensability of the microscope in this system. In other words, the photos obtained without using microscope aren't able to be used as the detection input.
On the basis of system's working normally, we further have the idea whether we can simplify the system. As a result, we propose a dichotomous model with only two types viz. 'normal use' and 'not recommended'. Considering that 'normal use' and 'not recommended' type face masks both can protect people effectively, we merge them into one type named 'normal use'. Accordingly, the other type is 'not recommended'. In the test samples, the number of 'normal use' is 60 (54 samples are detected correctly) and 'not recommended' is 27 (23 samples are detected correctly). To counterbalance the uneven distribution of samples, we assign the weight viz. 60 87 and 27 87 to each type. As expected, the accuracy becomes better and increases to 88.51%. Since there are two types, it is easier for the model to tell which type the detected face mask belongs to. In some simple cases, we may consider this scheme.
Besides the system mentioned above being able to be used to detect its service life, some conditions of the face mask itself may also affect their use life. For example, there may be lint inside the face mask when using face mask a few times. In that case, we can choose to discard the mask and use a new one to ease the discomfort. Meanwhile, if the face mask being used gets wet by accident, we must stop using it whatever stage it belongs to.
In this paper, we propose a service stage detection method based on a mobile microscope which can be used to obtain the micro-photos of the face mask being used.
In our detection method, we first get the micro-photos of face mask being used, which may reflect some details such as droplets or other obvious dirt. Then, we extract texture features from the micro-photos using the method of GLCM and choosing four measures viz. contrast, correlation, energy and homogeneity as the features. Subsequently, KNN method is applied to work on the detect the service stage. In validation experiments, the obtained system achieves a relatively good result with a precision of 82.87%±8.50% on the testing dataset. The result of our experiments provide an idea of using photos to detect the use time of face masks to distinguish whether the face mask can be used sequentially or not. Faced with the current severe situation of COVID-19 and possible shortage of face masks, our research may work as an assistant to help the common people to use face masks more correctly. Furthermore, it can exert positive influence on pro-tecting uninfected people and stopping the possibly infected patients from spreading virus.
In future research, based on the current portability and practicability, we will try using a more stable algorithm to reach the goal of achieving a higher accuracy. Besides, different types of face masks should be taken into consideration to expand the types of detecting objects.