简体   繁体   中英

OpenCV, C++: How to use cv::Meanshift

I have a vector of 2-D points, I am trying to use the meanshift algorithm to detect multiple modes in the data but am a bit confused by the method signature.

1) Can I pass in my vector (if so in what form) or must I conver to cv::Mat (if so how? if I have points with negative values).

2) How do I extract the multiple modes, from what I can see the function only returns an int

Thanks

OpenCV's implementation of mean shift is for tracking a single object (as part of the CamShift algorithm ) and therefore I don't believe it has been extended to track multiple objects using multi-modal distributions. It will give you a bounding box centered on the mode of a probability image (returned by the reference pass of cv::Rect window ).

Is your data represented as a mixture of Gaussians (or some other symmetric distribution)? If so you might be able to use k-means clustering to find the means of your distribution (which will be the mode for a symmetric distribution), although choosing k will be problematic.

Alternatively, a hack that might enable tracking of multiple objects (or finding multiple modes) could involve repeated calling this function, retrieving the mode and then zeroing this section from the back projected histogram.

As for your data's form, the function input is through a cv::Mat so you will have to convert your data. However, you claim to have negative values and this opencv function expects a probability histogram (which typically you calculate from an image using cv::calcBackProject() ) so I expect it will complain if you try to pass it a cv::Mat containing negative values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM