OpenCV kmeans binary image

219 Views Asked by At

I'm trying to use opencv kmeans function at the binary image but I don't know how to setup the its parameters.

My final goal is to find the to two centers of blob.

binary_image_files

    vector<Point2f> centers;
    Mat points;

    findNonZero(binary_image, points);
    points.convertTo(points, CV_32F);



    kmeans(points, overlapped, Mat(), TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 10, 1.0), 3,
    KMEANS_PP_CENTERS, centers );

First parameter requires Specific Format. So I tried to fix it but it has an error

Actually, I don't know how to use the Kmeans function at binary image specifically.

Can you help me how to use it?

1

There are 1 best solutions below

0
On
    vector<Point2f> centers;
    Mat points;
    Mat labels;
    findNonZero(temp, points);
    points.convertTo(points, CV_32F);


    
    kmeans(points, overlapped, labels, TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 10, 1.0), 3,
    KMEANS_PP_CENTERS, centers );

It was simple problem. I changed third parameters.

Thank you!