TLD (tracking-Learning-detection) learning and source code understanding (5)

Source: Internet
Author: User
Tags tld

The following is my understanding of the Code in my thesis and the analysis of these experts. However, it is not long since I have been involved in image processing and machine vision. In addition, my programming skills are weak, therefore, there may be many errors in the analysis process. I hope you will not correct them. In addition, because programming is not understood in many places, the comments are messy and haihan is still involved.

Lktracker. h

# Include <tld_utils.h> # include <opencv2/opencv. HPP> // use the pyramid LK Optical Flow Method for tracking. Therefore, many of the class member variables are the class lktracker {PRIVATE: STD: Vector parameter of the calcopticalflowpyrlk () function in opencv. <CV :: point2f> pointsfb; CV: Size window_size; // int level of the search window size for each pyramid layer; // The maximum number of pyramid layers STD: vector <uchar> status; // array. If the optical flow of the corresponding feature is found, each element in the array is set to 1; otherwise, it is set to 0 STD: vector <uchar> fb_status; STD: vector <float> similarity; // similarity STD: vector <float> fb_error; // forward-backward error method. Evaluate the fb_error result and compare it with the Euclidean distance of the original position, discard the float simmed; float fbmed; // The termcriteria template class from the tracing results with too much distance, replacing the previous cvtermcriteria, this class is the termination condition of the iteration algorithm. // three parameters are required for this class of variable. One is the type, the second parameter is the maximum number of iterations, And the last parameter is a specific threshold. // Specify the termination condition for the iteration process of the optical flow for a certain point at each pyramid layer. CV: termcriteria term_criteria; float Lambda; // threshold ?? Lagrangian Multiplier // NCC normalized crossover correlation. The combination of FB error and NCC makes the tracking more stable crossover-related image matching algorithm ?? // The cross correlation method is used for short-term prediction of moving clouds. The GMS-5 satellite cloud maps were selected for two consecutive times, and the cloud maps were divided into 32 × 32 pixels. The cross correlation method was used to obtain the best matching areas of the two cloud maps, determine the moving vectors (velocity and direction) of each image subset based on the location and time interval of the matching area of the front and back cloud maps, and objectively analyze the moving vectors of the image subset, then, based on the cloud/graph moving vector set after the test, the backward trajectory method is used to make a short-term prediction of the cloud map. Void normcroscorrelation (const CV: mat & img1, const CV: mat & img2, STD: vector <CV: point2f> & points1, STD: vector <CV :: point2f> & points2); bool filterpts (STD: vector <CV: point2f> & points1, STD: vector <CV: point2f> & points2); public: lktracker (); // tracking of feature points ?? Bool trackf2f (const CV: mat & img1, const CV: mat & img2, STD: vector <CV: point2f> & points1, STD: vector <CV :: point2f> & points2); float getfb () {return fbmed ;}};

 

Lktracker. cpp

# Include <lktracker. h> using namespace CV; // pyramid LK Optical Flow Method tracking // media flow mid-value optical flow tracking plus tracking error detection // constructor, initialize the member variable lktracker: lktracker () {// This type of variable requires three parameters, one being type, the second being the maximum number of iterations, And the last being a specific threshold. Term_criteria = termcriteria (termcriteria: Count + termcriteria: EPS, 20, 0.03); window_size = size (0.5); Level = 5; Lambda =;} bool lktracker :: trackf2f (const mat & img1, const mat & img2, vector <point2f> & points1, vector <CV: point2f> & points2) {// todo!: Implement C function cvcalcopticalflowpyrlk () or faster tracking function // forward-backward tracking // median stream Tracking Method Based on forward-backward error // pyramid LK Optical Flow Method tracking // forward trajectory forward track calcopticalflowpyrlk (img1, img2, points1, points2, status, similarity, window_size, level, term_criteria, lambda, 0); // backward trajeclk back track calcopticalflowpyrlk (img2, img1, points2, pointsfb, fb_status, fb_error, win Dow_size, level, term_criteria, lambda, 0); // compute the real FB-error // The principle is very simple: From the point of the T-moment image, tracking point B of the image at the t + 1 moment; then back, tracking back from point B of the image at the t + 1 moment, // If tracking the point C of the image at the T moment, in this way, the forward and backward trajectories are generated, and the distance between point A and point C in T is compared. If the distance // is smaller than a threshold value, the forward tracing is considered correct; this distance is fb_error // calculation of the forward and backward trajectory error for (INT I = 0; I <points1.size (); ++ I) {fb_error [I] = norm (pointsfb [I]-points1 [I]); // evaluate the matrix or Vector norm ?? Absolute value?} // Filter out points with fb_error [I] <= median (fb_error) & points with sim_error [I]> median (sim_error) normcroscorrelation (img1, img2, points1, points2); Return filterpts (points1, points2 );} // use NCC to take a 10*10 small image around the tracking and prediction result and a 10*10 small image around the original position (obtained using the getrectsubpix function) enter/line template match (call matchtemplate) void lktracker: normcroscorrelation (const mat & img1, const mat & img2, vector <point2f> & points1, vector <point2f> & poi Nts2) {mat rec0 (10, 10, cv_8u); MAT rec1 (10, 10, cv_8u); MAT res (, cv_32f); For (INT I = 0; I <points1.size (); I ++) {If (status [I] = 1) {// 1 indicates that the feature point has been successfully tracked. // The former frame and the current frame are in the image (centered on each feature point ?) Extracts 10x10 pixels of a rectangle. getrectsubpix (img1, size (10, 10), points1 [I], rec0), getrectsubpix (img2, size (10, 10), points2 [I], rec1); // match the 10x10 pixel rectangle extracted from the previous frame and the current frame to obtain the matched ing image // cv_tm_ccoeff_normed normalization correlation coefficient matching method // The parameters are: the image to be searched. Search for templates. The mapped image of the comparison result. Specify the matching method matchtemplate (rec0, rec1, res, cv_tm_ccoeff_normed); similarity [I] = (float *) (res. data) [0]; // obtain the similarity of each feature point} else {similarity [I] = 0.0 ;}} rec0.release (); rec1.release (); Res. release ();} // filter out fb_error [I] <= median (fb_error) and sim_error [I]> median (sim_error) the Feature Points of // obtain the values of NCC and Fb error results, respectively, remove bool lktracker: filterpts (vector <point2f> & points1, vector <point2f> & points2) {// get er Ror medians simmed = median (similarity); // find the size_t I, K; for (I = k = 0; I <points2.size (); ++ I) {If (! Status [I]) continue; If (similarity [I]> simmed) {// feature of similarity [I]> simmed points1 [k] = points1 [I]; points2 [k] = points2 [I]; fb_error [k] = fb_error [I]; k ++ ;}} if (k = 0) return false; points1.resize (k); points2.resize (k); fb_error.resize (k); fbmed = median (fb_error); // find the value of fb_error for (I = k = 0; I <points2.size (); ++ I) {If (! Status [I]) continue; If (fb_error [I] <= fbmed) {/points1 [k] = points1 [I]; // further filter the remaining feature points in the previous step, with the remaining feature points: fb_error [I] <= fbmed points2 [k] = points2 [I]; k ++ ;}} points1.resize (k); points2.resize (k); If (k> 0) return true; else return false;}/** old opencv stylevoid lktracker: Init (MAT img0, vector <point2f> & points) {// preallocate // pyr1 = cvcreateimage (SIZE (img1.width + 8, img1.height/3), ipl_depth_32f, 1 ); // pyr2 = cvcreateimage (SIZE (img1.width + 8, img1.height/3), ipl_depth_32f, 1); // const int num_pts = points. size (); // status = new char [num_pts]; // track_error = new float [num_pts]; // fb_error = new float [num_pts];} void lktracker :: trackf2f (..) {values (& img1, & img2, pyr1, pyr1, points1, points2, points1.size (), window_size, level, status, track_error, term_criteria, latency); cvcalcopticalflowpyrlk (& img2, & img1, pyr2, pyr1, points2, pointsfb, points2.size (), window_size, level, 0, 0, term_criteria, criteria | cv_lkflow_pyr_a_ready | cv_lkflow_pyr_readb_y );}*/

 

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.