OpenCV KNNロードトレーニング済みモデル

4792 ワード


 
 1 #include
 2 #include 
 3 using namespace cv;
 4 using namespace std;
 5 #include "test.h"
 6 
 7 int main()
 8 {
 9     ///******************** ***************************///
10     Mat test = imread(".\\test\\3.jpg", 0);// 
11     Mat bw;
12     threshold(test, bw, 0, 255, CV_THRESH_BINARY);
13     Mat samples = bw.reshape(0, 1);
14     samples.convertTo(samples, CV_32F);
15     //  KNN , 
16     const int K = 4;//testModel->getDefaultK()  
17     Ptr Model = StatModel::load("KnnTest.xml");
18     Mat MatResult(0, 0, CV_32F);//   
19     Model->findNearest(samples, K, MatResult);//knn  
20     //21     //Ptr Model = StatModel::load("KnnTest.xml");
22     //Mat test = imread(".\\test\\3.jpg", 0);// 
23     //Mat bw;
24     //threshold(test, bw, 0, 255, CV_THRESH_BINARY);
25     //Mat I0 = bw.reshape(0, 1);
26     //I0.convertTo(I0, CV_32F);
27     ////  KNN , 
28     //float r = Model->predict(I0);    
29 }