0
$\begingroup$

I'm moving my project from Python's libraries to opencv, and I have one big problem.

In Python skylearn, I have kmeans object, which has two useful methods: fit_predict and fit, which both are nescessery for my project.

The problem is I can't find any equivalent in opencv. There is only function cv::kmeans, which is not enough for me.

When I'm using Python skylearn the pseudo code of my program looks like:

kmeans.fit_predict(train_data) // it gaves me labels, and compute centers

kmeans.predict(test_sample) // it gaves me labels for test sample computed from centers which were computed above

Is there any equivalent or way to do the same in opencv?

$\endgroup$
0
$\begingroup$

The OpenCV kmeans function is equivalent to fit(). It returns the cluster centers, and you can use this to implement your own predict()function. For a new sample, calculate the distance to each of the cluster centers. The cluster with the lowest distance is the predicted class.

| improve this answer | |
$\endgroup$
  • $\begingroup$ You're right, I did it and it works like I need. $\endgroup$ – bielu000 Dec 17 '18 at 6:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.