Connected Component Labelling


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: 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:


Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s