fork download
  1. #include <iostream>
  2. #include <opencv2/opencv.hpp>
  3. #include <opencv2/core/core.hpp>
  4. #include <opencv2/highgui/highgui.hpp>
  5. #include <opencv2/ml.hpp>
  6. #include <opencv2/core.hpp>
  7. #include <opencv2/imgproc.hpp>
  8. #include "opencv2/imgcodecs.hpp"
  9. #include <opencv2/highgui.hpp>
  10. #include <opencv2/ml.hpp>
  11.  
  12. using namespace cv::ml;
  13. using namespace cv;
  14. using namespace std;
  15.  
  16.  
  17.  
  18. int main()
  19. {
  20. Mat img = imread("/home/pixar/Desktop/rmi.jpeg",0);
  21.  
  22. int numFiles = 1;
  23.  
  24. Size Imgsize(64,124);
  25.  
  26. resize (img, img, Imgsize);
  27.  
  28.  
  29. int ImgArea = 64 * 124 ;
  30.  
  31.  
  32. Mat tarain (numFiles,ImgArea,CV_32FC1);
  33.  
  34. int ii = 0;
  35.  
  36. cout << tarain.rows << endl << tarain.cols <<endl;
  37. for (int i = 0; i < img.rows; i++)
  38. {
  39.  
  40. for (int j =0; j < img.cols; j++)
  41. {
  42.  
  43. tarain.at<float>(0, ii++) = img.at<uchar>(i,j);
  44. }
  45. }
  46.  
  47. Mat labels(1,1,CV_32SC1);
  48. labels.rowRange( 0, 1).setTo(2);
  49.  
  50. Ptr<SVM> svm = SVM::create();
  51.  
  52. // used for n class classification
  53. svm->setType(SVM::C_SVC);
  54.  
  55. //
  56. svm->setKernel(SVM::LINEAR);
  57.  
  58.  
  59.  
  60. Mat a;
  61. svm->train(tarain,ROW_SAMPLE, labels);
  62.  
  63. svm->save("sa.xml");
  64. int r = svm->predict(tarain, a,1);
  65. cout << r <<endl << a << endl;
  66.  
  67.  
  68. waitKey(0);
  69. return 0;
  70. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:30: fatal error: opencv2/opencv.hpp: No such file or directory
 #include <opencv2/opencv.hpp>
                              ^
compilation terminated.
stdout
Standard output is empty