OpenCV KNearest input
What is the exact meaning of the first parameter that takes the KNearest class in OpenCV, CvMat* trainData?
Do I have to pass a CvMat* with the location of the centroids of the classes, or another info?
As said here, it's the cache of all training samples, ie: you need an initial set. After that, you could request for all new vectors which are the closest in the training set. kNN is a classifier (that's why it inherits from CvStatModel. A typical used is: you have a training set of features computed from what you want, says ORB features from a dataset of images (but not limited to keypoints!) and you want to know for an unknown image, what is it. You train your kNN with the training set (ie: the features computed on each images you know the class), you compute the features on your unknown image, and you find the k nearest neighbors in the training set (with find_nearest). You look at the label of each of the nearest neighbors, and the majority label is probably the class for your image => you have recognize and image. This is just a typical used of kNN and there is many others!
If you are looking for a solution to cluster a group of data into K class (ie: for a set of vector, you want to make a partition into k groups), look at kmeans.