It is said that in the later version of opencv, the condensation Algorithm for CV of particle filtering has been removed. The previously learned condensation algorithm cannot be developed in C ++ or only in C, (a previous article about particle filter used to achieve mouse tracking ).
To use particle filter tracking, we can use http://web.engr.oregonstate.edu /~ The particle filter code provided by Hess/particle filter has many variants. Rob Hess should be the most basic one. Sampling
Importance resampling (SIR), sampling based on importance. The following is an explanation of this:
{
1) initialization stage-extract tracking target features
In this phase, you need to manually specify the tracking target, and the program calculates the characteristics of the Tracking target. For example, you can use the color features of the target. Specific to rob Hess code, you need to manually drag a tracking area at the beginning, and then the program automatically calculates the histogram of the hue space in the area, that is, the target feature. The Histogram can be expressed by a vector, so the target feature is a vector V of N * 1.
2) search phase-dog placement
Well, we have mastered the characteristics of the target. Below we release a lot of dogs to search for the target object. Here the dog is the particle. There are many ways to release a dog. For example, a) Uniform placement: uniformly Scattering Particles (Uniform Distribution) on the entire image plane; B) Moving them near the target obtained in the previous frame according to Gaussian distribution, it can be understood that more places are placed near the target, and less places are placed away from the target. Rob Hess's Code uses the latter method. How can a dog search for a target after it is released? It is the target feature (color histogram, vector v) obtained in the initialization phase ). Each dog calculates the color feature of the image at its position, obtains a color histogram and vector VI, and computes the similarity between the histogram and the target histogram. Similarity has multiple measurements. The simplest one is to calculate sum (ABS (Vi-V )). each dog calculates the similarity and then normalize it again, so that the similarity obtained by all dogs is equal to 1.
3) decision-making stage
A clever dog we put out reported to us, "the similarity between the image of No. 1 dog and the target is 0.3", and "the similarity between the image of No. 2 dog and the target is 0.02 ", "the similarity between the image at DOG 3 and the target is 0.0003," and "the similarity between the image at dog n and the target is 0.013 "... so where is the goal most likely? Let's make a weighted average. Set the pixel coordinate of the Image of dog n to (Xn, yn). The reported similarity is wn, so the most likely pixel coordinate of the target x = sum (XN * wn ), y = sum (YN * wn ).
4) resampling
Since we are tracking the target, in general, the target is running around in disorder. Where can the target be in a new image? Let's search for a dog. But how should we put a dog? Let's review the report from the dogs. "The similarity between the image of No. 1 dog and the target is 0.3", "the similarity between the image of No. 2 dog and the target is 0.02", and "the similarity between the image and the target of No. 3 dog is 0.0003 ", "the similarity between the image and the target of dog n is 0.013 "... according to the reports of all dogs, the similarity between dogs 1 and 3 is the highest, and the similarity between dogs 3 is the lowest. Therefore, we need to re-distribute police forces, we put more dogs in the dog with the highest similarity, less dogs in the dog with the lowest similarity, and even recall the original dog. This is sampling.
Importance resampling, re-sampling based on importance (more important ).
(2)-> (3)-> (4)-> (2) if the loop is repeated, the dynamic tracking of the target is completed.
According to my rough understanding, the core idea of particle filtering is random sampling + importance sampling. Since I don't know where the target is, I should randomly scatter the particles. After scattering the particles, the importance of each particle is calculated based on the feature similarity. Then, the particles are scattered in important places, and less scattered in unimportant places. Therefore, compared with Monte Carlo filtering, particle filtering requires less computation. This idea coincides with the ransac algorithm. The idea of ransac is also (for example, it is used in the simplest linear fitting). Since I don't know what the linear equation is, I will calculate a straight line first from two random points, then let's see how many points match my line. Which line can obtain the support of the most points, and which line is the target line. The idea is very simple, but it works well.
}
Code. Rob Hess's code was written on Linux, and the kind person who handed in the code was slightly changed ~ Who will teach me? I won't ~ (>_< )~), Enables Windows + vs2010 to run. In track1.c, the main function is used to process the attached video by default. Of course, you can easily change it to input the video from the camera (cvcapturefromcam ). I used opencv2.4.0, But I didn't test the earlier version. After the program starts, after reading the first image, you need to drag the target area of the tracking with the mouse (then press Enter ). The tracking area is faster than the hour. When the tracking area is large, it becomes very difficult. The Code also requires the support of The GSL library, which is configured with gsl_vs2010. Particle Filter tracks vs2010 project code.