[Opencv] camshiftdemo Target Tracking

Source: Internet
Author: User
1. Introduction

There is another opportunity in the past two days (Why ?) Use camshift tracking in opencv. A simple record is a supplement to this object tracking and learning note _ 1 (application of the meanshift and camshift examples in opencv ).

2. Workflow

2.1 usage

  • If trackobject is set to 0, it indicates that no trace is performed. If trackobject is set to 1 after the (new) tracking area is selected, trackobject is set to-1. Data to be tracked is prepared according to the new window (color space conversion, histogram, etc.) --- all of the above Code comments have mentioned
  • I just read the source code to find that I can pause by P and then select the tracking target. This logic is quite useful.

The source code involved in 2.2 is:

$ Opencv_home/samples/CPP/camshiftdemo. cpp

$ Opencv_home // modules/Video/src/camshift. cpp: a total of four functions

  • CV: camshift
  • CV: meanshift
  • Cvcamshift
  • Cvmeanshift

2.3 call process:

CV: camshift (...) --> cvcamshift (...) --> cvmeanshift (...)

  • I) cvcamshift adjusts the size of the input window. Specifically, the four rectangular sides expand the tolerance pixels outward. Cross-border processing is automatically performed. Tolerance hard coded is 10.
  • Ii) Calculate moments for the expanded rectangular tracking area. If the zero moment is less than dbl_epsilon,-1 is directly returned.
  • Iii) dbl_epsilon: the first 28 digits are printed on the local machine as follows: 0.0000000000000002220446049250

Note: Previously, CV: camshift initialized a cvconnectedcomp with a value of 0 and passed in cvcamshift. After cvcamshift is returned, use this comp change to pass in the most initial tracing window of CV: camshift.

Therefore, if-1 is returned, the initial window (trackwindow in camshiftdemo) is 0. The following error is returned at the next frame:

Camshift. cpp: 81: Error: (-5) Input window has non-positive sizes in function cvmeanshift

This is also a small bug. In this case, the system prompts that no windows are tracked, or the current tracing window (whose m00 is 0) is assigned to _ comp before-1 is returned, in this way, the tracking window should be kept in that small area until a new area is selected-I tried this and the drawing error occurs again. It should be because the area is too small to fit Elipse. Whatever...

In the processing of each frame, there are basically three places that may change the initial tracking window (note that the initial window is for each frame, rather than the initial window selected by the mouse)

  1. The final convergence result of cvmeanshift itself
  2. In cvcamshift, the window extension after cvmeanshift, that is, the I above)
  3. An Algorithm of camshift to adjust the size of the tracking window based on the second moment

3. The end

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.