Computational Intelligence in Image Processing 2018View this Special Issue
Research Article | Open Access
Water Quality Monitoring Method Based on TLD 3D Fish Tracking and XGBoost
Aiming at the problem of water quality monitoring, this paper presents a method of biological water quality monitoring based on TLD (Tracking-Learning-Detection) framework and XGBoost (eXtreme Gradient Boosting). Firstly, under the framework of TLD, an independent tracking system is designed; TLD captures 3D coordinate information of fish based on video and calculates the behavior of fish movement parameters which can reflect the change of water quality via processing the coordinate information of the fish body. The data of coordinate information will be more prominent via the data processing. The integration of all built XGBoost water quality monitoring model which is based on characteristic parameters; the model was used to analyze and evaluate fish behavior parameters under unknown water quality to achieve the purpose of water quality monitoring.
In the era of Industrial 4.0, highly automated and intelligent manufacturing technology will gradually occupy the field of human society in the field of industrial development. In the field of water quality pollution, an efficient, convenient, and intelligent monitoring method becomes more urgent and necessary. In order to prevent and deal with the current situation of water quality pollution, the existing water quality monitoring technologies are physical and chemical analysis technology, automatic detection technology, and biological monitoring technology [1, 2]. The physical and chemical analysis technology and automatic detection technology for long-term real-time monitoring cost are relatively large; at the same time, these two technologies can not achieve the comprehensive evaluation of water pollution degree. The biological monitoring technique has been adopted. Biological monitoring technology is comprehensive, rich, and continuous; in recent years it plays an increasingly important role and has a broad application prospect in the environmental assessment. In the monitoring of biological water quality, fish, as an important indicator organism, with its movement characteristics, physiological characteristics, and other information directly reflect the changes in the water environment and the current situation of environmental pollution. Many scholars such as Kim et al. obtain the parameters of motion behavior of fish by computer vision technology [3–8]; only a few scholars put forward the method of water quality anomaly monitoring according to these characteristic parameters. Serra-Toro et al., Lai and Chiu, and Zhangzan et al., respectively, analyze the fish swimming behavior to get the relationship between exercise behavior parameters and water quality via recursive algorithm, fuzzy reasoning method, and data evaluation, so as to achieve the purpose of monitoring the abnormal water quality [9–11].
Although these methods can be used for monitoring, there are a lot of defects in the selection of feature parameters, the length of operation, the accuracy of monitoring, and the processing of individual differences. The choice of parameters has great influence on the model; the model cannot choose effective parameters to monitor; it can only be passively chosen by human choice; because the monitoring process of these methods was divided into a plurality of independent links, from data acquisition to the final monitoring, the whole operation was too long to show the results in time and effectively; data acquisition and processing process was too complex; each link increases the error component data, resulting in low accuracy of monitoring results. It only selects features unilaterally; the sample data can not reflect the difference, the sample can not be comprehensively taken into account, and the monitoring results also are one-sided.
This paper presents the water quality monitoring methods under the framework of TLD and XGBoost; based on 3D fish tracking, we use TLD method to get the fish body coordinate in different water conditions and determine the characteristic parameters based on the calculation results of fish movement parameters. XGBoost is adopted to analyze and evaluate the feature parameter, establishing semantic mapping, and the movement of fish behavior characteristic parameters model, and finally it realized the abnormal water quality monitoring.
2. Extraction of Fish Characteristic Parameters
2.1. TLD Framework Introduction
TLD was a long-term single objective tracking algorithm proposed by Dr. Kalal et al. [12, 13]. The TLD framework mainly includes three parts: tracking part, learning part, and detection part. The relationship of the three parts and the tracking process is shown in Figure 1, for tracking part, mainly using the Forward-Backward Error method, using Lucas-Kanade optical flow tracking, the tracking results using Forward-Backward Error as feedback, the Euclidean distance for FB error compared with the original position, the distance which the longer will be abandon, this tracking method of using FB error to discard bad values was called Median Flow, which discards those larger than 50% of the European distance set; detection of TLD has three parts: the variance classifier module, set classifier module, and nearest neighbor classifier module; these three classifiers are cascaded. Each scan window of the current frame sequentially passes through the above three classifiers, both are considered to contain foreground objects; the learning part is the same as in other methods of target detection; detection module in TLD may also have errors, and the error was nothing more than the two cases being negative sample error and positive sample error. The learning module is used according to the results of the tracking module to evaluate the two kinds of errors of detection module, based on the results of the assessment to generate the target training samples and update the detection module; meanwhile, the tracking module “key points” were updated, in order to avoid similar mistakes.
2.2. Fish Tracking Framework
We put forward a more specific framework for fish tracking based on the framework of TLD. Imitating TLD settings, the process of track is also divided into three parts, each part of the connection is as shown in Figure 2; we collected video by frame rate interception and input it to the TLD tracking module.
At any time, the tracked target could be represented by its state property. The state property can be a tracking box that represents the location and size of the target, or a marker that identifies whether the tracked target was visible. The two-track box in the space domain similarity was used to measure the overlap; the calculation method is that the two track frame intersections have joint segmentation. The shape of the object was represented by image patch P, and each fish body image was sampled from the tracking frame and normalized to the same size. In the tracking module, NCC is said to be the normalized correlation coefficient; BF (brute force selection mechanism) is said to be the forced choice mechanism, tracking each pixel in a first frame in the whole fish body image sequence; FB (Forward-Backward Error) was used to estimate trajectory. Finally, through the interaction of NCC and BF, we can get the stable tracking point by taking the two intersections.
The fish body images were not only input to the tracking module, but also used in the detection module. The test needs to use the positive and negative training sample information for training in advance, so that the detection module has certain detection ability. The detection module includes three filters, respectively, Variance filter, Fern variance filter (Random-Fern), and NN filter; through the three filters the errors in image are removed and the best target fish image is obtained. The tracking module and the detection module obtain the sample information to be fused and input to the learning module. Learning module used P-N learning. The main idea was that the detector error can be identified by two types of constraints. The function of P-expert was to find the new appearance (deformation) of the target and to increase the number of positive samples. The role of N-expert was to generate negative training samples. The premise of N-expert was that the tracked object may only appear in a position in the video frame, so if the position of the foreground target is determined, all around it must be a negative sample. The learning module was used to correct the tracking module and the detection module, and the Fern structure would be updated, and the weight is adjusted to make the next result more reliable.
The image of the fish captured by the video was processed by the above steps, and finally the coordinate information of the fish in the three-dimensional space was obtained. Because the TLD tracking result was the two-dimensional plane coordinate information, the camera position needs to be arranged in order to collect three-dimensional coordinates. The camera was placed in the vertical direction and the horizontal direction of the fish tank, as shown in Figures 3(a) and 3(b); the two pictures show our camera positioning; in order to facilitate viewing, vertical plane and horizontal plane with a fish tank were drawn out; the blue side is said to be the vertical direction to the information acquisition of -; the green part is said to be the horizontal direction to the information acquisition of -.
The position of some fish in the space is as shown in Figure 4. Figures 4(a) and 4(c) show that the fish coordinate point projected onto a plane and get the scatterplot. In (b), (d) the blue oval line in the graph represents different points in different plane; elliptical is said to be in a different point in different plane. So you can see clearly the distribution of fish in the three-dimensional space. The -axis of the two cameras overlap, and the -axis overlap information is removed to get the 3D information of the -- surface.
2.3. Parameter Calculationa
The trajectory of fish can be expressed as a series of discrete discontinuous points; that is to say, the trajectory of video sequence images of a fish can be described as Getting fish behavior characteristic parameters which can reflect the status of the water ecological environment by using trajectory: average moving distance, speed, acceleration, direction discrete distance, direction discrete distance, and distribution area, the definitions are as follows.
Average moving distance: and are used to represent the coordinates of the starting point and the end point of the fish target tracking trajectory in unit time. Speed would be defined as Acceleration a would be defined as, respectively, expressed the speed of .
The distribution of fish in a single plane has great difference between normal and abnormal water quality; we use measured dispersion to describe the relationship between the single fish and fish. The dispersion formula would be defined asThe characteristics of the dispersion of the fish body coordinates were concerned with the position of the center of gravity and the center of gravity of each individual, which integrates the characteristics of the whole and the individual. Similarly, in the - plane, the distribution area of fish also has great features. Shoal area calculation formula is represents the maximum distance between coordinates of all individuals in a fish at the same time, is said to be the maximum distance between coordinate; is said to be the fish gathered together to form the minimum circumscribed circle radius. Finally, we use TLD and especially placed cameras to collect the coordinates; the characteristic parameters are obtained through calculation to establish a large enough data set.
3. Establishment of Water Quality Monitoring Model
XGBoost (eXtreme Gradient Boosting) [14, 15] is designed by Dr. Chen Tianqi in Gradient Machine (GBDT) and the GBDT has been improved in boosting. On the basis of GBDT, XGBoost modified the objective function and loss function.
3.1. Objective Function, Obj
First of all, the objective function of GBDT is as follows: where is the loss function, is a regular term, and is tree complexity. After series of processing, we get a new objective function which is easier to use: XGBoost Taylor expansion for makes it more similar to our previous goals. The process is as follows: By applying Taylor expansion to the three terms, we can make it clear that the final objective function depends on the first derivative and the second derivative of the error function of each data point.
Definition: Bring (9) and (10) back to (8): Taking into account the square loss, can also continue to (10): In this way, we can remove the constant term and get the new objective function: In the equation, .
Then define the complexity of the tree: where is a leaf vector, is a tree structure, which defines the complexity of the number of nodes in a tree, and is square of the output of each tree node. Under this new definition, we can rewrite the objective function as follows: is defined as a set of samples on each leaf; .To further simplify the formula, we define Based on the derivation of it being equal to 0, the following can be obtained: Bring the optimal solution back to (18), and the final objective function is obtained: The above objective function, Obj, represents the maximum amount of reduction in the target when the structure of a tree is specified. You can call it a structural score. The smaller the Obj, the better the structure of the tree.
3.2. Add Scoring Function Gain
represents the left subtree fraction, represents the right subtree fraction, represents an undivided score, and represents the complexity cost of adding new leaf nodes. For each expansion, or to efficiently enumerate all possible segmentation schemes, suppose you want to enumerate all the conditions of , for a particular split a to calculate a’s left and right derivative, as shown in Figure 5.
It would be found that for all ‘a’, you can give all the gradients and GL and GR as long as a scan is done from left to right. And then the above formula can be used to calculate the score of each partition.
3.3. XGBoost Biological Water Quality Monitoring Model
XGBoost joined the regularization; regularized boosting was a great help in reducing overfitting. Compared with GBDT the XGBoost can achieve parallel processing; the speed has been greatly improved; comparing SVM classification with XGBoost, XGBoost allows the user to define custom optimization objectives and evaluation criteria; it will add a new dimension in the model, so it is not subject to any restrictions on the data processing; in the process of data collection, because various artificial or experimental defects exist, it will inevitably lead to the phenomenon of data loss; while the XGBoost was built to deal with the missing value rules, the user needs to provide a different values sample and then take it as a parameter input; so this value is taken as missing values; XGBoost has different treatment methods in different nodes encountered with missing values and will learn when encountering the missing value in the future how to deal with it. The method provides a good solution for the deletion of the fish characteristic parameters, and the XGBoost allows the use of cross validation in each round of boosting iteration. Therefore, the optimal number of boosting iterations can be easily obtained; XGBoost can continue to train on the results of the previous round. This feature was a great advantage in the application of the classification of fish characteristic parameters and can realize the continuity of the model.
Therefore, we try to use XGBoost to replace the previous classifier to establish water quality classification model. Prior to the establishment of the model, we need to preprocess the collected feature data to improve the training speed and accuracy of the model. Firstly, Smoothing was performed to create a feature sample set. XGBoost was an excellent decision tree classifier, which can use the objective function and scoring function as the model’s performance.
XGBoost water quality classification model: In this paper, the steps of establishing water quality monitoring model were as follows:
We use the TLD technology to preprocess the fish motion parameters and set up a set of characteristic parameters.
The feature parameter set was used as the input of XGBoost for training.
Cross validation method was used to obtain the optimal number of boosting iterations.
The tree structure and the characteristic score were used to analyze and evaluate the model.
The algorithm flow was shown in Algorithm 1.
4. Experimental Results and Analysis
In the fish red carp, body length was about 3 cm; the camera is BNT shadow (HD720) and using tank; normal water quality is common water; abnormal water is chemical reagent which is added to copper or chromium.
In order to verify the validity and feasibility of the method in this paper, the following experiments are designed. Get the fish motion video images of normal and abnormal water quality by using the digital camera in the course of the experiment; each frame size was , the frame of 25 f/s.
4.1. Select Characteristic Parameters
In order to improve the speed of data processing and the classification accuracy of XGBoost classifier, we set the parameters selection and choose normal water quality data set; the abnormal water quality data was intercepted according to certain sampling frequency. The characteristic parameters of the six groups were selected as follows: near distance, , speed, , acceleration, , , dispersion direction, and , dispersion direction and distribution area , as shown in Figure 6.
In Figure 6 the color changes from blue to red, showing the water quality change from normal water quality to abnormal water quality. Left with blue is said to be the healthy state; right with red is said to be the unhealthy water quality. It can be observed from Figure 6 that characteristic parameters have obvious trend; in normal water, acceleration , speed , near distance , dispersion direction, and dispersion direction in the direction of the image on the left were less active; in each image the number of difference changes was low; and the right was risk quality, comparing characteristic parameter changes with the left; there was a significant difference.
4.2. Feature Parameter Preprocessing and Sample Set
The preprocessing of the characteristic parameters was to remove the gross errors in the data by Rajda (3) criterion.
Due to the normalization of XGBoost own data normalization, here were no longer repeat operation.
The concrete steps to build a sample set were as follows:
The original data of fish motion parameters were obtained by randomly selecting 2000 frames of images under normal and abnormal water quality.
Set up the original data sample set, including training samples 2000 6 (normal and abnormal water quality of each 1000 6) and test samples 2000 6 (normal and abnormal water quality of each 1000 6).
Preprocess the original data.
4.3. Experimental Result
A total of 4 sets of samples were established in this experiment; we use these data for testing; test results were shown in Table 1. As can be seen from the table, the classification accuracy and time all have an excellent performance. Because the data were too much, here we choose the last set of data: original data 4 for detailed instructions. Using XGBoost the output of the classification model of original data 4 is obtained; the model of the code in the name of the characteristics of the parameters is shown in Table 2. The score of each characteristic parameter in the model was shown in Figure 7.
The specific weight of each characteristic parameter for the overall sample set and their respective classification accuracy were shown in Table 3. It can be seen from the chart during the classification processing, that the model selects the most obvious characteristic parameters; for those weak characteristic parameters, model was used to adjust the weight of its classification, especially particularly bad data directly discarded. The model iterates over each feature parameter and can be used to segment the training set by calculating the eigenvalues of each feature parameter and then using tree structured Figure 8 to view the decision-making process (3rd boosted tree). In Figure 8, the feature and the feature values for each split were shown as well as the output leaf nodes. The split decisions with each node and the different colors for left and right splits (blue and red) were also shown.
4.4. Model Evaluation and Optimization
4.4.1. -Fold Cross Validation
This time the cross validation process is to repeat the experiment for times, each time from the sections to choose a different part as test data (ensure that the part of the data was tested separately) and the rest of the test data as training data for experiment. Finally, the obtained experimental results are average. The verification results were shown in Table 4. It includes both the mean (Accuracy%) and standard deviation (Error%) classification accuracy. As can be seen from the table, XGBoost as a classifier can still maintain a high accuracy after multiple cross validation, and the time used for each classification was very small.
4.4.2. Loss Function and Classification Error
Using XGBoost as a decision tree classifier, we can also use the loss function and classification error to evaluate our water quality classification model, as shown in Figure 9. -axis abscissa represents the number of data.
The Log Loss function is very common as the evaluation criteria; in Figure 9, you can clearly see the model loss decreases and reaching the ideal state. The classification error is divided into two kinds: one is the training error (Train), another is test error (Test); the training error stabilized at around 0.010 and the test error finally remains at a very low value and can fully meet the application of our water quality classification model.
We optimize the processing speed of the model and use the computer multicore processor (CPU) to improve the speed of the model. From a cost point of view, the price of a single core CPU was cheaper, but the speed of computing compared with multicore CPU comparison has great gap. From Figure 10 we can see that when the number of processors in the core model selection gradually increased, the processing speed of the model has great changes too, because the test data from the scale is still relatively small, not enough to fully display the processing speed of the model, but the advantages of multicore processor in speed optimization still can be seen.
4.6. Comparison between XGBoost and SVM
SVM is one of the current mainstream classifiers that has always been a very good performance in the classification problem; in order to demonstrate the performance of the XGBoost classifier, we made a comparison between SVM and XGBoost. Because the kernel function of SVM will affect the classification results, in order to allow the SVM classifier to achieve the best working condition, we adopted the previous laboratory work ; using RBF kernel parameters, the penalty factor is given in Table 5. XGBoost uses the data set for original data 4; in order to play the best working condition, SVM needs to be further normalized on the basis of original data 4.
The final SVM classification effect is shown in Figure 11.
As shown in Figure 12, compared with the accuracy of the classification and the time used in the classification, XGBoost has a huge advantage, especially the advantages of classification time; XGBoost is faster than SVM to speed up to two orders of magnitude. Details are shown in Table 5.
We obtain 3D coordinates by tracking fish in the water. A series of motion characteristic parameters which can be used to represent the water quality were calculated; in the processing of parameters, we found that some features can be used to distinguish between normal and abnormal water quality. According to this idea, water quality monitoring model was set up based on XGBoost classifiers. After a large number of experiments, this model can realize the water quality classification quickly, accurately, and conveniently. Compared with the previous classifier, XGBoost was more outstanding. However, the whole process of water quality monitoring can not achieve closure, so we must rely on line training and human error processing; the whole system can not achieve real-time monitoring. We will further strengthen the model’s ability to distinguish. In the analysis of the feature image, the processing of the intermediate state can be transformed into the frequency domain by the way of signal processing, removing interference information, and improving the accuracy of early warning. And as a follow-up we can deteriorate the experimental environment and enhance the robustness of the system.
Conflicts of Interest
The authors declare that they have no conflicts of interest.
This work is supported by the National Natural Science Foundation of China (Grant no. 61601400) and the Postdoctoral Scientific Research Project of Hebei Province (Grant no. B2016003027).
- V. Simeonov, P. Simeonova, S. Tsakovski, and V. Lovchinov, “Lake water monitoring data assessment by multivariate statistics,” Journal of Water Resource and Protection, vol. 2, no. 4, pp. 353–361, 2010.
- A. Jang, Z. Zou, K. K. Lee, C. H. Ahn, and P. L. Bishop, “State-of-the-art lab chip sensors for environmental water monitoring,” Measurement Science and Technology, vol. 22, no. 3, Article ID 032001, 2011.
- M. C. Kim, W. M. Shin, M. S. Jeong et al., “Real-time motion generating method for artifical fish,” Computer Science and Network Security, vol. 10, no. 7, pp. 52–61, 2007.
- K. Nimkerdphol and M. Nakagawa, “Effect of sodium hypochlorite on zebrafish swimming behavior estimated by fractal dimension analysis,” Journal of Bioscience and Bioengineering, vol. 105, no. 5, pp. 486–492, 2008.
- H. Ma, T.-F. Tsai, and C.-C. Liu, “Real-time monitoring of water quality using temporal trajectory of live fish,” Expert Systems with Applications, vol. 37, no. 7, pp. 5158–5171, 2010.
- C. Jiujun, X. Gang, Y. Xiaofang et al., “Fish activity model based on tail swing frequency,” Journal of Image and Graphics, vol. 14, no. 10, pp. 2177–2180, 2009.
- H. Jianglong, F. Jinglong, and W. Daquan, “Water quality monitoring using multi-object tracking algorithm,” Journal of Mechanical & Electrical Engineering, vol. 29, no. 5, pp. 613–615, 2012.
- S.-H. Cheng, J. Cai, and C.-H. Hu, “Fish motion tracking research based on video algorithm,” Guangdian Gongcheng/Opto-Electronic Engineering, vol. 38, no. 2, pp. 14–18, 2011.
- C. Serra-Toro, R. Montoliu, V. J. Traver, I. M. Hurtado-Melgar, M. Núñez-Redó, and P. Cascales, “Assessing water quality by video monitoring fish swimming behavior,” in Proceedings of the 2010 20th International Conference on Pattern Recognition, ICPR 2010, pp. 428–431, August 2010.
- C.-L. Lai and C.-L. Chiu, “Using image processing technology for water quality monitoring system,” in Proceedings of the 2011 International Conference on Machine Learning and Cybernetics, ICMLC 2011, pp. 1856–1861, Guilin,China, July 2011.
- J. Zhangzan, X. Gang, C. Jiujun et al., “Anomaly detection of water quality based on visual perception and V-detector,” Information and Control, vol. 40, no. 1, pp. 130–136, 2011.
- Z. Kalal, K. Mikolajczyk, and J. Matas, “Tracking-learning-detection,” IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 34, no. 7, pp. 1409–1422, 2012.
- Z. Kalal, K. Mikolajczyk, and J. Matas, “Face-TLD: tracking-learning-detection applied to faces,” in Proceedings of the 17th IEEE International Conference on Image Processing (ICIP '10), pp. 3789–3792, Hong Kong, China, September 2010.
- T. Chen and C. Guestrin, “XGBoost: a scalable tree boosting system,” in Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, KDD 2016, pp. 785–794, August 2016.
- T. Chen, T. He, and M. Benesty, “xgboost: Extreme Gradient Boosting,” 2017.
- S. Cheng and J. Liu, “A method of water quality monitoring based on computer vision and SVM,” Opto-Electronic Engineering, vol. 5, pp. 28–33, 2014.
Copyright © 2018 Shuhong Cheng et al. This is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.