As you may know, a lot has changed in OpenCV 3. In the previous version of OpenCV, I did it like this:
Mat trainData(classes * samples, ImageSize, CV_32FC1); Mat trainClasses(classes * samples, 1, CV_32FC1); KNNLearning(&trainData, &trainClasses); //learning function KNearest knearest(trainData, trainClasses); //creating //loading input image Mat input = imread("input.jpg"); //digital recognition learningTest(input, knearest);//test
I also found an example of how to understand this, but I still have errors in the create function:
Ptr<KNearest> knearestKdt = KNearest::create(ml::KNearest::Params(10, true, INT_MAX, ml::KNearest::KDTREE)); knearestKdt->train(trainData, ml::ROW_SAMPLE, trainLabels); knearestKdt->findNearest(testData, 4, bestLabels);
Can you provide me with information on how to correctly rewrite the actual KNearest code to openCV 3?
source share