I am looking for an OpenCV function that can find connected components and perform a few tasks on them ( like getting the number of pixels, contour, list of pixels in the object etc.. )

Is there a function of OpenCV (C++) that is similar to MatLab's regionprops ?


Solution 1:

Starting from version 3.0, OpenCV has connectedComponents function.

Solution 2:

Have a look at the cvFindContours function. It's very versatile -- it can find both interior and exterior contours, and return the results in a variety of formats (e.g. flat list vs. tree structure). Once you have the contours, functions like cvContourArea allow you to determine basic properties of the connected component corresponding to a particular contour.

If you prefer to use the newer C++ interface (as opposed to the older C-style interface I described above), then the function names are similar.