Ask Your Question

Revision history [back]

findContours returns a vector<vector<Point>>. When using an enhanced for-loop (like the one you have in your code) to iterate over a container, it goes inside and extracts the element and stores it in your variable cont.

For your case though, when it tries to iterate over contours, it finds out that there is another vector inside it hence the failure. To fix this, you need to state what kind of element is inside the container.

for(vector<Point>cont: contours)
{
    Moments mu = moments(cont, false);
}

Thumb Rule: When dealing with container of container; like contours, and using an enhanced for-loop to access its elements, always state the type of container it will be extracting.