Background Subtraction
Based on OpenCV, extract the moving target by using the background subtraction algorithm.
Those three pictures show three different stages in Background Subtraction. Firstly, I use functions called findContours() and convexHull() to extract the targets contour. Then, I fill the contour part, like the second and the third picture, which is used to build a voxel to track with in the next step.
Prediction Algorithm(Average Weighted)
OpenCV provide several functions to do the tracking work, I find two ways cv2.createBackgroundSubtractorMOG2() and cv2.createBackgroundSubtractorKNN(). Here, 'MOG2' is using GMM(Guassian Mixture Model), which applied different Gaussian distribution to each pixel. This function also have a variable called detectShadow, which can perform the shadow (distinguished with the target).
Considering my test is not influenced by the shadow so much. Also, I want to make it real-time. I write a simple algorithm rather than using MOG2(). I calculate the next voxel position based on positions of adjacent voxels. I applied the different weight to the different voxel, the closer the voxel it is, the higher the weighted value is.
Demo