Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to implement K nearest neighbour

Hello,

I am trying to use KNN but calling Im not sure how to initialize it. CvKNearest knn; does not work. It says CvKNearest is undefined. I followed this http://docs.opencv.org/2.4/modules/ml/doc/k_nearest_neighbors.html#

Is there a documentation that teaches me how to initialize classes in opencv ?

How to implement K nearest neighbour

Hello,

I am trying to use KNN but calling Im not sure how to initialize it. CvKNearest knn; does not work. It says CvKNearest is undefined. I followed this http://docs.opencv.org/2.4/modules/ml/doc/k_nearest_neighbors.html#

Is there a documentation that teaches me how to initialize classes in opencv ?? I did this

flann::Index flan;

Mat M = (Mat_<double>(3, 3) << 1, 1, 1, 2, 2, 2, 3, 3, 3);

Mat query = (Mat_<double>(1, 3) << 1, 1, 1);
Mat index, dist;


flan.knnSearch(query, index, dist, 2);

But how do I tell the function to search the K nearest neighbour of Mat query given M (the data) ? It is giving me an error also, OpenCV Error: Assertion failed (query.type() == type && indices.type() == CV_32S && dists.type() == dtype) Help thanks. OpenCV is too hard for me.