#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/ml.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include "opencv2/imgcodecs.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/ml.hpp>
using namespace cv::ml;
using namespace cv;
using namespace std;
int main()
{
Mat img = imread("/home/pixar/Desktop/rmi.jpeg",0);
int numFiles = 1;
Size Imgsize(64,124);
resize (img, img, Imgsize);
int ImgArea = 64 * 124 ;
Mat tarain (numFiles,ImgArea,CV_32FC1);
int ii = 0;
cout << tarain.rows << endl << tarain.cols <<endl;
for (int i = 0; i < img.rows; i++)
{
for (int j =0; j < img.cols; j++)
{
tarain.at<float>(0, ii++) = img.at<uchar>(i,j);
}
}
Mat labels(1,1,CV_32SC1);
labels.rowRange( 0, 1).setTo(2);
Ptr<SVM> svm = SVM::create();
// used for n class classification
svm->setType(SVM::C_SVC);
//
svm->setKernel(SVM::LINEAR);
Mat a;
svm->train(tarain,ROW_SAMPLE, labels);
svm->save("sa.xml");
int r = svm->predict(tarain, a,1);
cout << r <<endl << a << endl;
waitKey(0);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8b3BlbmN2Mi9vcGVuY3YuaHBwPgojaW5jbHVkZSA8b3BlbmN2Mi9jb3JlL2NvcmUuaHBwPgojaW5jbHVkZSA8b3BlbmN2Mi9oaWdoZ3VpL2hpZ2hndWkuaHBwPgojaW5jbHVkZSA8b3BlbmN2Mi9tbC5ocHA+CiNpbmNsdWRlIDxvcGVuY3YyL2NvcmUuaHBwPgojaW5jbHVkZSA8b3BlbmN2Mi9pbWdwcm9jLmhwcD4KI2luY2x1ZGUgIm9wZW5jdjIvaW1nY29kZWNzLmhwcCIKI2luY2x1ZGUgPG9wZW5jdjIvaGlnaGd1aS5ocHA+CiNpbmNsdWRlIDxvcGVuY3YyL21sLmhwcD4KCnVzaW5nIG5hbWVz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