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?

Answers


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.


Need Your Help

SQL query - Select * from view or Select col1, col2, … colN from view

sql sql-server

We are using SQL Server 2005, but this question can be for any RDBMS.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.