kmeans in java

asked 2013-09-26 11:28:23 -0500

lasmi gravatar image

updated 2013-09-26 12:12:23 -0500

Hi! I want to use the function kmeans but I don't understand how I can use that in Java. In c++ the syntax is: double kmeans(InputArray data, int K, InputOutputArray bestLabels, TermCriteria criteria, int attempts, int flags, OutputArray centers=noArray() )

I want to apply this on an image to cluster colors. How can I do in Java! Help me please!

This is my code:

IplImage labels = cvCreateImage(cvSize(1, 1), 8, CV_32F); double [] centers = null; CvArr c = null;

cvKMeans2(src, 2, labels,cvTermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0),1, null,0, c, centers);

src is my image!

I have this error:

OpenCV Error: Assertion failed (labels.isContinuous() && labels.type() == CV_32S && (labels.cols == 1 || labels.rows == 1) && labels.cols + labels.rows - 1 == data.rows)

Why?? What is labels?

edit retag flag offensive close merge delete

Comments

just out of curiosity: why did you put all those hash signs i front of your tags ?

http://docs.opencv.org/java/org/opencv/core/Core.html#kmeans(org.opencv.core.Mat,%20int,%20org.opencv.core.Mat,%20org.opencv.core.TermCriteria,%20int,%20int)

berak gravatar imageberak ( 2013-09-26 11:35:26 -0500 )edit

that's (deprecated) c-api code again, not java

berak gravatar imageberak ( 2013-09-26 12:23:22 -0500 )edit

@berak: java api is an incapsulation of c++ library! my code is in java!

lasmi gravatar imagelasmi ( 2013-09-28 09:18:44 -0500 )edit