# Revision history [back]

What is a contour?

A contour is basically a set of points that are connected to each other. Opencv's function cv::findCountours returns a vector with as many elements as there are isolated sets of connected pixels in the image, and this is also known as a 'blob'. Each of this elements in the vector is no more than a list of Points that contain the (x,y) coordinates of each pixel in the blob.

Why are these contours so useful?

Blob analysis is a very important area of computer vision and is used in many applications (such as part inspection, simple object detection and much more). Many applications consist in treating the raw image in such a way that the objects of interest that are to be examined become white blobs, and everything that is not an object of interest (background / other objects) are black. An image in which the objects of interest are white blobs and everything else is black is called a binary image.

Blobs are used so much because they contain a lot of information. OpenCV has a lot of functions that output important information about those, and here are some examples:

cv::Point calculateBlobCentroid(const std::vector<cv::Point> blob)
{
cv::Moments mu = cv::moments(blob);
cv::Point centroid = cv::Point (mu.m10/mu.m00 , mu.m01/mu.m00);

return centroid;
}


This function returns the centroid of a blob.

arcLength(InputArray curve, bool closed)


Returns the perimeter of the blob

boundingRect(InputArray points)


Returns a rectangle that encloses the blob

contourArea(InputArray contour, bool oriented=false )


Returns the area of the blob (number of white pixels).

You can check all the information you can get from a contour in the following link http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html .

About the trouble you're having with watershed, please check this link, where you can find a very nice tutorial on how to apply that method and and how it works. https://opencv-code.com/tutorials/count-and-segment-overlapping-objects-with-watershed-and-distance-transform/

Good luck

What is a contour?

A contour is basically a set of points that are connected to each other. Opencv's function cv::findCountours returns a vector with as many elements as there are isolated sets of connected pixels in the image, and this is also known as a 'blob'. Each of this elements in the vector is no more than a list of Points that contain the (x,y) coordinates of each pixel in the blob. outer contour of the blob.

Why are these contours so useful?

Blob analysis is a very important area of computer vision and is used in many applications (such as part inspection, simple object detection and much more). Many applications consist in treating the raw image in such a way that the objects of interest that are to be examined become white blobs, and everything that is not an object of interest (background / other objects) are black. An image in which the objects of interest are white blobs and everything else is black is called a binary image.

Blobs are used so much because they contain a lot of information. OpenCV has a lot of functions that output important information about those, and here are some examples:

cv::Point calculateBlobCentroid(const std::vector<cv::Point> blob)
{
cv::Moments mu = cv::moments(blob);
cv::Point centroid = cv::Point (mu.m10/mu.m00 , mu.m01/mu.m00);

return centroid;
}


This function returns the centroid of a blob.

arcLength(InputArray curve, bool closed)


Returns the perimeter of the blob

boundingRect(InputArray points)


Returns a rectangle that encloses the blob

contourArea(InputArray contour, bool oriented=false )


Returns the area of the blob (number of white pixels).

You can check all the information you can get from a contour in the following link http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html .

About the trouble you're having with watershed, please check this link, where you can find a very nice tutorial on how to apply that method and and how it works. https://opencv-code.com/tutorials/count-and-segment-overlapping-objects-with-watershed-and-distance-transform/

Good luck