0

I need to track moving shapes in opencv.

Until now I am able to draw the countours around the moving shapes:

cv::Mat lastFrame, maskFrame;
std::vector <std::vector <cv::Point>> contours;
// background substraction and frame processing  ... 
findContours(maskFrame, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
drawContours(lastFrame, contours, -1, cv::Scalar(0), 2);

but I don't know how to track them.

If I have a shape in frame(n), I would like to know if this shape is also present in frame(n - 1) maybe knowing the area & the position of each shape in both frames.

Do you have some suggestion on how to do it ? Maybe using some class that I obviously don't know ?

2
  • 1
    the easiest way is to calculate the center of each contour (each contour is represented by a set of points) and store it. In the next frame you do the same and check the distance between the detected contours with similar shape and size from the previous and the current frame.
    – GpG
    Commented Jan 3, 2017 at 21:02
  • This is nice. I see that with moments class I can determine the center of the shape. Great.
    – szlak
    Commented Jan 3, 2017 at 21:09

0

Browse other questions tagged or ask your own question.