0

So, I'm trying to find the centers of the white clusters with OpenCV in the next frame:

*screenshot made with OpenCV imshow()*

I've already tried the HoughGradient function, but it's results were inconsistent, since these clusters weren't circle-like shapes in all frames. Any other suggestions?

  • http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#moments – berak May 16 '15 at 17:39

2 Answers2

1

I think you have two options.

  1. Use connected components to find the blobs, and because you know they are circular do some estimation about their centers. The drawcontours function on the OpenCV documentation has a good example of how to find connected components using contours: http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#drawcontours

  2. If you know that your blobs are white / white-ish, you can find the indices of all the pixels that are close in color to white / white-ish, and manually reconstruct each set of indices into a connected component.

(potentially related post: OpenCV Object Detection - Center Point)

Community
  • 1
  • 1
mprat
  • 2,451
  • 15
  • 33
0

as @berak pointed out, you can use moments to find centroid of blobs

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;

Point getCentroid( InputArray Points )
{
    Point Coord;
    Moments mm = moments( Points, false );
    double moment10 = mm.m10;
    double moment01 = mm.m01;
    double moment00 = mm.m00;
    Coord.x = int(moment10 / moment00);
    Coord.y = int(moment01 / moment00);
    return Coord;
}

int main( int argc, char* argv[] )
{
    Mat src = imread( argv[1] );

    Mat gray;
    cvtColor( src, gray, CV_BGR2GRAY );
    gray = gray > 127;

    Mat nonzeropixels;
    findNonZero( gray, nonzeropixels );

    Point pt = getCentroid( nonzeropixels );
    rectangle(src, pt,pt, Scalar(0, 255, 0), 2);

    imshow("result",src);
    waitKey();

    return 0;
}

test images & results : ( green dot is centroid of white blobs )

enter image description here enter image description here

enter image description here enter image description here

sturkmen
  • 3,495
  • 4
  • 27
  • 63