This article is not a detailed explanation, just a summary of my use of meanshift some of the experience
Let's talk about the principle of the Meanshift algorithm:
As shown, specify an area first, by comparing the geometry center of the specified area with the quality, if the difference is large, move the geometry center of the area to the centroid, and then proceed with the comparison. Until the geometric center of the area coincides with the centroid. In this way, you can find the most densely populated area of a picture.
To apply Meanshift to target tracking is to construct a PDF of a running picture, and then apply the above gradient-climbing idea to find the most dense area. The basic ideas are as follows:
1 Select a target a in frame a
2 According to the relationship between B-frame and a, get the PDF of B
3 Meanshift method to find the most dense area of the probability density, this area is considered to be the position of the target in B-frame
How to construct a PDF diagram, I found two methods:
1 The histogram of target A is first obtained, and the histogram is used to reverse the projection in B-frame. The so-called reverse projection is actually very simple. is to use the gray value of each pixel in the B-frame as the corresponding value in the histogram of target a. After such a reverse projection, if the value of a point in the reverse projection of B-frame is particularly large, it is assumed that the original pixel value in the point is particularly large in the target, and that the point is a particular point in the target.
Of course, the disadvantage of this method is very large. In particular, when the target and background gray level is not very large, this method is not very effective.
This method of course also has the advantage, is that the algorithm is faster, I do not have any optimization of the case, 1 seconds to handle 100 frames.
2 in the B-frame to find an area of the same size as target a, the region named B, then the histogram of B, and then compare the histogram of A and b the difference between the histogram, with a value to represent the difference, and replace this value in B-frame pixel values.
Two vectors of a histogram and B histogram can be normalized, using the dot product of these two vectors to represent the difference between them, the greater the difference, the greater the angle of the two normalized vectors, the smaller the dot product. If the difference is smaller, the smaller the angle of the two normalized vectors, the greater the dot product. Using their dot product instead of the pixel value in B frame, by moving B in frame B, all the points in B frame can be represented by a dot product, and the greater the value of this dot product, the closer the region corresponds to the target. This gives you a PDF of frame B.
Once this is done, the meanshift algorithm can be used to ramp up the gradient and find the location closest to the target area.
The robustness of this method is better, but the processing speed is not faster than the last method.
Meanshift Application to target tracking