参考:http://www.aiuxian.com/article/p-620963.html
http://blog.csdn.net/lifeitengup/article/details/8866078
opencv2机器学习库MLL
- #include <iostream>
- #include <opencv2/core/core.hpp>
- #include <opencv2/highgui/highgui.hpp>
- #include <opencv2/ml/ml.hpp>
- #define NTRAINING_SAMPLES 100 // Number of training samples per class
- #define FRAC_LINEAR_SEP 0.9f // Fraction of samples which compose the linear separable part
- using namespace cv;
- using namespace std;
- void help()
- {
- cout<< "\n--------------------------------------------------------------------------" << endl
- << "This program shows Support Vector Machines for Non-Linearly Separable Data. " << endl
- << "Usage:" << endl
- << "./non_linear_svms" << endl
- << "--------------------------------------------------------------------------" << endl
- << endl;
- }
- int main()
- {
- help();
- // Data for visual representation
- const int WIDTH = 512, HEIGHT = 512;
- Mat I = Mat::zeros(HEIGHT, WIDTH, CV_8UC3);
- //--------------------- 1. Set up training data randomly ---------------------------------------
- Mat trainData(2*NTRAINING_SAMPLES, 2, CV_32FC1);
- Mat labels (2*NTRAINING_SAMPLES, 1, CV_32FC1);
- RNG rng(100); // Random value generation class
- // Set up the linearly separable part of the training data
- int nLinearSamples = (int) (FRAC_LINEAR_SEP * NTRAINING_SAMPLES);
- // Generate random points for the class 1
- Mat trainClass = trainData.rowRange(0, nLinearSamples);