1

I have a binary image with multiple blobs. I want to find the number of pixels in each blob. My version of openCV is below 3.0, so I don't have connectedComponents function. I was trying findContourinstead. If the image is im, I execute findContour as:

cv::findContours(im.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);

Now, size of contour[i] or contourArea(contours[i]); don't really give the number of pixels. Is there any other function to find the number of pixels in each blob?

A post recommends cvBlobslib library but is there an inbuilt function in OpenCV (version lower than 3.0)?

1 Answer 1

3

If upgrading your OpenCV is not an option, you still can take the implementation of connectedComponents from OpenCV3.0 and plant it into your own code. OpenCV is an open source project. You can get implementation of connectedComponents() from gitHub.

There are other ways to get the number of pixels, but they are really inefficient. For example you can use drawContours() function to draw contours found by findContours() one by one on some empty image, and use countNonZero() to count number of non-black pixels.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.