Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connected components in OpenCV

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 ?

like image 508
EyalG Avatar asked Oct 02 '12 10:10

EyalG


People also ask

What is connected components in digital image processing?

A connected component is a set of connected pixels that share a specific property, V. Two pixels, p and q, are connected if there is a path from p to q of pixels with property V. A path is an ordered sequence of pixels such that any two adjacent pixels in the sequence are neighbors.

How are connected components implemented in Python?

Applying Connected Component Labeling in Python: Connected Component Labeling can be applied using the cv2. connectedComponents() function in OpenCV. The function is defined so as to show the original image and the image after Connected Component Labeling. The input the the function is the path to the original image.

What is connected set in image processing?

Connected components, in a 2D image, are clusters of pixels with the same value, which are connected to each other through either 4-pixel, or 8-pixel connectivity.


2 Answers

Starting from version 3.0, OpenCV has connectedComponents function.

like image 198
Alessandro Jacopson Avatar answered Oct 07 '22 19:10

Alessandro Jacopson


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.

like image 43
mpenkov Avatar answered Oct 07 '22 21:10

mpenkov