Analysis of CMT Tracking algorithm of computer vision CV Four

Source: Internet
Author: User

1 Prefacein the previous section we have analyzed the scaling and rotation of the computed feature points, where the method of removing bad feature points is finally analyzed. 2 final Step analysisThe basic idea of vote is that the relative distance of these characteristic points relative to the center is relatively constant after taking the scaling rotation into account, that is to say, the position of the relative center of the next frame's characteristic point is invariable. but because the image itself changes, it is impossible to get exactly the same relative position, at this time, some will be near the center, some will deviate greatly. Then, the author chooses the largest class as the best feature point by using the clustering method. The others don't.
The above figure should be a good understanding of the process. Then look at the author's own official online map of the people should be able to understand. The author of the code found a cluster of libraries to do, specifically I did not delve into:
void Consensus::findconsensus (const vector<point2f> & points, const vector<int> & classes, cons T float scale, const float rotation, POINT2F & Center, vector<point2f> & Points_inlier, Vector<int  > & classes_inlier) {//if No points is available, Reteurn nan If (points.size () = = 0) {center.x =        Numeric_limits<float>::quiet_nan ();        Center.y = Numeric_limits<float>::quiet_nan ();    Return    //compute votes calculates the poll: The basic method is to maintain a relatively consistent relative position of the points relative to the normalization and calculate their rotation and scaling vector<point2f> votes (points.size ()); for (size_t i = 0; i < points.size (), i++) {votes[i] = points[i]-scale * rotate (points_normalized[classes[    I]], rotation);    } T_index N = Points.size (); float * D = new float[n* (N-1)/2];    This was a lot of memory and so we put it on the heap Cluster_result Z (N-1);    Compute pairwise distances between votes//calculates the relative distance between votes points int index = 0; for (size_t i = 0; i< Points.size (); i++) {for (size_t j = i+1; J < Points.size (); j + +) {//todo:this index calculation is cor            Rect, but is it a good thing?            int index = i * (Points.size ()-1)-(i*i + i)/2 + j-1;            Calculate relative distance D[index] = Norm (Votes[i]-votes[j]);        index++;    }} mst_linkage_core (N,d,z);    Union_find nodes (N);    Sort linkage by distance ascending std::stable_sort (z[0], z[n-1]);    S is cluster sizes int * s = new int[2*n-1]; Todo:why does this loop go to 2*n-1? Shouldn ' t it be simply N?    Everything > N gets overwritten later for (int i = 0; i < 2*n-1; i++) {s[i] = 1; } T_index parent = 0; After the loop ends, the parent contains the index of the last cluster for (node const * nn=z[0); NN!=Z[N-1];        ++NN) {//Get the data points whose clusters is merged in step I.        Find the cluster identifiers for these points. T_index Node1 = nodEs.        Find (NN-&GT;NODE1); T_index Node2 = nodes.        Find (NN-&GT;NODE2); Merge the nodes in the Union-find data structure by making them//children of a new node//if the Dista NCE is appropriate if (Nn->dist < Thr_cutoff) {parent = nodes.            Union (Node1, Node2);        S[parent] = S[node1] + S[node2];    }}//get cluster labels int * T = new Int[n]; for (T_index i = 0; i < N; i++) {T[i] = nodes.    Find (i);    }//find largest cluster int s_max = distance (s, max_element (s, S + 2*n-1));    Find inliers, Compute center of votes Points_inlier.reserve (S[s_max]);    Classes_inlier.reserve (S[s_max]);    center.x = CENTER.Y = 0;        for (size_t i = 0; i < points.size (); i++) {//if, point are in consensus cluster If (t[i] = = S_max)            {Points_inlier.push_back (points[i]);            Classes_inlier.push_back (Classes[i]);            Center.x + = votes[i].x; CeNter.y + = Votes[i].y;    }} center.x/= points_inlier.size ();    Center.y/= points_inlier.size (); Delete[] d;delete[] s;delete[] T;}

This algorithm is used to get inlier
and then in the code, the author once again made a match, matchlocal, in my opinion and Findconsensus's purpose is the same, but also through the relative point of distance to determine whether the characteristics of the feature, and then do a match on these features, is selected in, Finally, the points of Inlier and the points of matchlocal are combined as the final feature points. the code for Matchlocal is as follows:
void matcher::matchlocal (const vector<keypoint> & keypoints, const Mat descriptors, const POINT2F Center, const float scale, const float rotation, vector<point2f> & points_matched, Vector<int> & Class    es_matched) {if (keypoints.size () = = 0) {return;    }//transform initial points vector<point2f> Pts_fg_trans;    Pts_fg_trans.reserve (Pts_fg_norm.size ()); for (size_t i = 0; i < pts_fg_norm.size (); i++) {//is also calculated relative position pts_fg_trans.push_back (scale * rotate (p    Ts_fg_norm[i],-rotation)); }//perform local matching for (size_t i = 0; i < keypoints.size (); i++) {//normalize KeyPoint with re        SPECT to center point2f location_rel = keypoints[i].pt-center;        Find potential indices for matching vector<int> indices_potential; for (size_t j = 0; J < Pts_fg_trans.size (); j + +) {//Calculate position deviation float l2norm = Norm (pts_fg_tr ANS[J]-Location_rel);            Set a threshold if (L2norm < Thr_cutoff) {Indices_potential.push_back (num_bg_points + j);        }}//if there is no potential matches, continue If (indices_potential.size () = = 0) continue; Build descriptor matrix and classes from potential indices mat database_potential = Mat (indices_potential.s        Ize (), Database.cols, Database.type ()); for (size_t j = 0; J < Indices_potential.size (); j + +) {Database.row (Indices_potential[j]). CopyTo (database_p        Otential.row (j));        }//find distances between descriptors vector<vector<dmatch> > matches;        Feature Matching Bfmatcher->knnmatch (Descriptors.row (i), database_potential, matches, 2) for selected feature points;        vector<dmatch> m = matches[0];        float Distance1 = m[0].distance/desc_length; float Distance2 = m.size () > 1?        M[1].distance/desc_length:1; if (Distance1 > Thr_dist) cOntinue;        if (Distance1/distance2 > Thr_ratio) continue;        int matched_class = Classes[indices_potential[m[0].trainidx]];        Points_matched.push_back (keypoints[i].pt);    Classes_matched.push_back (Matched_class); }}

Well, because of the time relationship, the CMT algorithm is analyzed here. There are a lot of shortcomings, may also be analyzed in place or even wrong, please criticize.
article original, reprint trouble Annotated Source: Blog.csdn.net/songrotek

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Analysis of CMT Tracking algorithm of computer vision CV Four

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.