Connected Component Labelling

Standard

Here’s connected component labelling code in C++ / OpenCV, that I whipped up, since I needed it for some other project and OpenCV doesn’t have it. Might as well just post it here for everyone.

Update: I added extra functions to find the component’s properties, such as area, centroid, and eccentricity, mostly based on the image moments derived from the blob.

It’s based on the two pass algorithm described here: http://en.wikipedia.org/wiki/Connected-component_labeling. Not the best algorithm, but fast enough, and works for what I needed, I’ll probably improve it when it’s required.

Here are some of the sample results:

Screen Shot 2014-06-06 at 19.33.10 Screen Shot 2014-06-06 at 19.34.35

Get the full code along with the examples here: https://github.com/subokita/Sandbox/tree/master/ConnectedComponent

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s