# An Improved Optical Flow Algorithm Based on Mask-R-CNN and K-Means for Velocity Calculation
## 3 Experiments and Evaluation
### The Evaluation of the Improved Optical Flow Algorithm for Velocity Calculation
#### 3.2.2 Experiment Two in the Circumstance with Many Moving Objects  
Experiment 1 considers the scene mainly with many cars. Compared with people, the moving direction of the cars is relatively assured. In order to verify the algorithm application in complex circumstance, experiment 2 is carried out in normal light with many people and other moving objects. Compared with the first experiment, experiment 2 is more complicated, because people have uncertain moving velocities and directions. The progress of dealing with images is shown in Figure 10.  
The comparison of the four different algorithms in velocity calculation is illustrated in Figure 11. To prove the superiority of the proposed algorithm, the quantitative comparisons with other algorithms are listed in Tables 5 and 6.  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline  & **LK** & **LK + Mask-R-CNN** & **LK + KM** & **LK + Mask-R-CNN + KM** \\ \hline RMSE & 1.6447 & 1.4352 & 1.0739 & 0.5677 \\ STD & 1.1686 & 1.0039 & 0.7867 & 0.4155 \\ \hline \hline \end{tabular}
\end{table}
Table 4: Velocity errors of four algorithms in the Y direction.  
Figure 9: (**a**) Velocity error in X direction of experiment 1; (**b**) velocity error in Y direction of experiment 1.  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline  & **LK** & **LK + Mask-R-CNN** & **LK + KM** & **LK + Mask-R-CNN + KM** \\ \hline RMSE & 3.6609 & 2.6738 & 2.0163 & 1.1772 \\ STD & 2.5952 & 1.8290 & 1.4750 & 0.8150 \\ \hline \hline \end{tabular}
\end{table}
Table 5: Velocity errors of four algorithms in the X direction.  
Although, there are more moving objects in the second scene than in the first one, the results are more fluctuant. However, it still performs better than the original algorithm. In complex environment, the proposed algorithm still has a good performance in velocity calculation. It can still recognize cars, people and other objects that are moving. Then, it calculates the optical value and the high of the images using only global motions. It reduces the quantity of singular optical value and makes the velocity error curve smoother and steadier than the original pyramid LK algorithm. The proposed algorithm also applies to where many people are walking. Also, it performs well in enhancing the accuracy and stability of vehicle velocity calculation. So, the improved pyramid LK algorithm is suitable for velocity calculation in complex environment with higher precision.  
\begin{table}
\begin{tabular}{c c c c c} \hline  & **LK** & **LK + Mask-R-CNN** & **LK + KM** & **LK + Mask-R-CNN + KM** \\ \hline RMSE & 4.6653 & 3.7348 & 2.5196 & 1.5841 \\ STD & 1.1686 & 2.7253 & 1.8408 & 1.1251 \\ \hline \end{tabular}
\end{table}
Table 6: Velocity errors of four algorithms in the Y direction.  
Figure 11: (**a**) Velocity error in X direction of experiment 2; (**b**) velocity error in Y direction of experiment 2.  
Figure 10: (**a**) The image in experiment 2; (**b**) the result of instance segmentation; (**c**) covering the objects with similar color masks.  
In the third experiment with dim light, the result of the other three algorithms is more fluctuant. The proposed algorithm performs well with stability and few errors. In dark environment, the proposed algorithm can still recognize the moving objects and cover them with dark masks. Then, it calculated the optical value and vehicle velocity by the images. It can be seen from Figure 13 that the original pyramid LK algorithm calculates the velocity with more errors in dark environment than that in normal light. However, the proposed algorithm can determine the correct pixel movement even in dim light and calculate the speed of the vehicle with higher precision.