TLD tracking algorithm optimization (I) parallelization

Source: Internet
Author: User
Tags tld

Just a few simple words, just ask your friends to exchange research.

Parallelism is not an improvement of algorithms, but a pursuit of real-time running.

A brief example is provided:

In the C ++ source code of the TLD algorithm:

Lktracker: trackf2f (const mat & img1, const mat & img2, vector <point2f> & points1, vector <CV: point2f> & points2 ){

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 # pragma OMP parallel sections // declare that the parallel area is divided into several sections, the running sequence between sections is parallel. {# pragma OMP section // The first section, which is completed by a thread independently. // The forward track is calcopticalflowpyrlk (img1, img2, points1, points2, status, similarity, window_size, level, term_criteria, lambda, 0); # pragma OMP section // the second section, which is independently completed by a thread. // The latter tracks calcop. Ticalflowpyrlk (img2, img1, points2, pointsfb, fb_status, fb_error, window_size, level, term_criteria, lambda, 0);} // forward track // calcopticalflowpyrlk (img1, img2, img2, points1, points2, status, similarity, window_size, level, term_criteria, lambda, 0); // backward track // calcopticalflowpyrlk (img2, img1, points2, pointsfb, fb_status, fb_error, window_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 the B point of the t + 1 moment image; then back from the B point of the t + 1 moment image tracking back, if the C-point of the T-moment image is tracked, the forward and backward trajectories are generated, and the distance between the-point and the C-point in the T-moment is compared. If the distance is smaller than a certain threshold, therefore, the forward tracking is correct. This distance is fb_error * // the error of calculating the forward and backward tracks. # Pragma OMP parallel for (INT I = 0; I <points1.size (); ++ I) {fb_error [I] = norm (pointsfb [I]-points1 [I]); // norm calculates the // norm of a matrix or vector, or 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 );}
After modification, the code running speed is improved a lot.

However, some problems must be considered for parallel processing.

1. Data mutex

2. Thread allocation problems

3. The release version application can be automatically optimized for the for loop. You do not need to set the for multi-thread. It is mainly used for modular data processing parallelization.


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.