Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track multiple object location?

Tags:

opencv

I need to track multiple objects, some color objects, attached on human body; All same color. I can track one object through Threshold image and Moment but when I use more than one object the computed Moment is something between those two or three. I need to have xy coordinate of each ones. Actually, after all, I want to do some analysis on those sequences of coordinates. I'm using VS2010, OpenCV 2.3.1, Win7 x64.

like image 850
Ehsan Avatar asked Feb 02 '26 01:02

Ehsan


1 Answers

You have to compute the moments for each blob alone. To accomplish this, you can use cv::findContours to get a descriptor for each blob in the form of its contour, then use it to compute its moments. In the code snippet below, inspired by this example, it is shown how one would compute the mass centers of each blob using this approach.

std::vector<std::vector<cv::Point> > contours;
std::vector<cv::Vec4i> hierarchy;

// Find contours
cv::findContours(img, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));

// Get the moments
std::vector<Moments> mu(contours.size() );
for(int i = 0; i < contours.size(); i++)
    mu[i] = moments(contours[i], false);

// Get the mass centers:
std::vector<cv::Point2f> mc(contours.size());
for(int i = 0; i < contours.size(); i++)
    mc[i] = Point2f(mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00);
like image 108
brunocodutra Avatar answered Feb 04 '26 00:02

brunocodutra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!