First time here? Check out the FAQ!

Ask Your Question
0

Unable to understand connectedComponents() in opencv [closed]

asked Jun 19 '16

Akash Garg gravatar image

I am writing a program wherein i need to use connectedCompponents(img, label, connectivity= 8, type= CV_32S ). All I know is that this function returns an integer stating the no of components in the image. Then what does Mat label suggest? Thanks in advance

Preview: (hide)

Closed for the following reason the question is answered, right answer was accepted by Akash Garg
close date 2016-07-12 04:25:05.230126

Comments

1

you can see this post too

LBerger gravatar imageLBerger (Jun 20 '16)edit

Thanks. The link was of great help!!!

Akash Garg gravatar imageAkash Garg (Jun 21 '16)edit

1 answer

Sort by » oldest newest most voted
2

answered Jun 20 '16

Tetragramm gravatar image

The input is a binary image. Any contiguous area (with connectivity 4 or 8, as per the argument) is given a label.

label is the same size as the input image, and of type CV_32S, as you passed the argument. Each pixel in label contains the number of the blob it belongs to, with 0 being no blob. You have a maximum label value of the return value - 1.

Preview: (hide)

Comments

So can I print the mat label? According to the explanation the background should be black and other objects having color corresponding to their label value.

Akash Garg gravatar imageAkash Garg (Jun 21 '16)edit

What do you want to actually do with it? Of course you can print it, but since I don't know what you're doing, I can't tell you if it does anything useful.

The background does have a value of 0, and anything above 0 is a blob.

Tetragramm gravatar imageTetragramm (Jun 22 '16)edit

Thank you so much!

Akash Garg gravatar imageAkash Garg (Jul 12 '16)edit

Question Tools

1 follower

Stats

Asked: Jun 19 '16

Seen: 216 times

Last updated: Jun 19 '16