OpenCV grouping of white pixels

I did the hard work by turning the iSight camera on my MacBook into an infrared camera, converted it, set a threshold, etc. and now has an image that looks something like this:

alt text

My problem is now; I need to know how many drops are in my image, grouping white pixels. I do not want to use cvBlob / cvBlobsLib , I would rather use what is already in OpenCV.

I can loop around the pixels and group them by checking the (threshold) touch of the white pixels, but I assume there is perhaps a very simple way to do this from OpenCV?

I assume that I can not use cvFindContours , as this will extract all white pixels in one large array, and not separate them into "groups". Can anyone recommend? (Please note that these are not circles, only the light emitted by the small IR LEDs)

Thank you very much in advance!
tommed

+7
c image-processing opencv imaging video-processing
source share
2 answers

Scroll through the image looking for white pixels. When you come across one, you use cvFloodFill with this pixel as a seed. Then increase the fill value for each area so that each area has a different color. This is called marking.

+8
source share

Yes, you can do this with cvFindContours() . It returns a pointer to the first sequence found. Using this pointer, you can go through all the sequences found.

  // your image converted to grayscale IplImage* grayImg = LoadImage(...); // image for drawing contours onto IplImage* colorImg = cvCreateImage(cvGetSize(grayImg), 8, 3); // memory where cvFindContours() can find memory in which to record the contours CvMemStorage* memStorage = cvCreateMemStorage(0); // find the contours on image *grayImg* CvSeq* contours = 0; cvFindContours(grayImg, memStorage, &contours); // traverse through and draw contours for(CvSeq* c = contours; c != NULL; c = c->h_next) { cvCvtColor( grayImg, colorImg, CV_GRAY2BGR ); cvDrawContours( colorImg, c, CVX_RED, CVX_BLUE, 0, // Try different values of max_level, and see what happens 2, 8 ); } 

Besides this method, I would advise you to take a look at cvBlobs or cvBlobsLib . The latter one is integrated into OpenCV 2.0 as the official blob detection library.

+4
source share

All Articles