# An Improved Optical Flow Algorithm Based on Mask-R-CNN and K-Means for Velocity Calculation
## 1 Introduction
Reaching out to new domains of motion analysis, the solution of the dense sampling problem can be done [25]. Based on the derived objective function in optical flow calculation, which formalizes the median filtering heuristic, [PERSON] and his team integrate flow estimations over large spatial neighborhoods and preserve motion details well [26]. Basically, the optical flow calculation methods mentioned above improve the accuracy of outputs by ameliorating the calculation process. In the Horn and Schunck algorithm [19], it is assumed that the optical flow field satisfies the constraints of global smoothness based on satisfying the basic optical flow equation. Smoothing constraints are applied to the whole optical flow field. It is based on dense optical flow computation. Each object point of the figure should be calculated, in order to obtain the optical flow vector of the points. However, in spare optical flow computation, only the point which can describe the motion characteristics of moving objects should be calculated. So, if the dense optical flow computation is used in our algorithm, the image processing speed of this method is sometimes slower than the input speed of video image sequence. The system processing is not real-time, and the algorithm calculation is complex. Also, spare optical flow computation improves the speed and efficiency of the operation. LK algorithm is one of the optical flow algorithms that are based on spare optical flow computation. The accuracy of dense optical flow is better than that of spare optical flow computation. The goal what we want to reach is to improve the accuracy of optical flow and velocity calculation. So, LK algorithm is more suitable for the experiment in the research. In the semi-visual odometry developed by the [PERSON] lab [27], pyramid LK algorithm is also applied to some extent. According to the assumption of invariant gray level, frame-to-frame pose estimation is realized by minimizing the gray value error of pixels. At the same time, the pyramid processing method is used to do the estimation. It starts from the top of the pyramid, and the results of the upper layer are taken as the initial values of the next layer, which are the same as the idea of the Pyramid LK. This method can improve the accuracy of the algorithm. However, these algorithms are not adaptable enough to accurately calculate the velocity of aircraft in complex environments, where people and other objects like animals and cars, which have motions relative to the ground, may lead to extra pixel movement. Environment noises resulting from interference of moving objects may result in wrong optical flow values and reduce the accuracy of vehicle velocity calculation. Optical flow method judges the movement of objects according to the movement of pixels between images. With the ground as the reference frame, if the objects on the ground remain unchanged during the UAV flight, the calculation result only includes the UAV flight speed. However, if the target takes the ground as the reference frame and has relative motion, the calculation result of optical flow method will include the target moving at the same time, thus introducing errors. When the velocity error is large, the navigation will be greatly disturbed. During the velocity calculation, there may be some moving objects inevitably in the two adjacent images captured by the UAV, such as people, animals, vehicles, etc. Indeed, motions captured by the UAV can be divided into two parts; global motions caused by the changes of background and local motions caused by moving foreground in the scene. As these motions have different speeds, the local motion may have serious impact on optical flow values. Considering these complex environments in optical flow calculation, this paper proposes an improved pyramid LK optical flow algorithm by combining Mask-R-CNN (Mask Region-based Convolutional Neural Network) [28] and K-Means [29] to reduce the impacts of extra moving pixels.