opencv学习笔记-openCV2与opencv3机器学习库MLL

这篇博客介绍了如何使用OpenCV2和OpenCV3的机器学习库MLL实现支持向量机(SVM)进行非线性与线性分类。通过生成随机数据点,展示SVM如何在二维平面上划分不同类别的点,并可视化决策边界。示例代码分别展示了非线性SVM和线性SVM的训练和预测过程。
摘要由CSDN通过智能技术生成

参考:http://www.aiuxian.com/article/p-620963.html

           http://blog.csdn.net/lifeitengup/article/details/8866078

opencv2机器学习库MLL

  1. #include <iostream>  
  2. #include <opencv2/core/core.hpp>  
  3. #include <opencv2/highgui/highgui.hpp>  
  4. #include <opencv2/ml/ml.hpp>  
  5.   
  6. #define NTRAINING_SAMPLES   100         // Number of training samples per class  
  7. #define FRAC_LINEAR_SEP     0.9f        // Fraction of samples which compose the linear separable part  
  8.   
  9. using namespace cv;  
  10. using namespace std;  
  11.   
  12. void help()  
  13. {  
  14.     cout<< "\n--------------------------------------------------------------------------" << endl  
  15.         << "This program shows Support Vector Machines for Non-Linearly Separable Data. " << endl  
  16.         << "Usage:"                                                               << endl  
  17.         << "./non_linear_svms" << endl  
  18.         << "--------------------------------------------------------------------------"   << endl  
  19.         << endl;  
  20. }  
  21.   
  22. int main()  
  23. {  
  24.     help();  
  25.   
  26.     // Data for visual representation  
  27.     const int WIDTH = 512, HEIGHT = 512;  
  28.     Mat I = Mat::zeros(HEIGHT, WIDTH, CV_8UC3);  
  29.   
  30.     //--------------------- 1. Set up training data randomly ---------------------------------------  
  31.     Mat trainData(2*NTRAINING_SAMPLES, 2, CV_32FC1);  
  32.     Mat labels   (2*NTRAINING_SAMPLES, 1, CV_32FC1);  
  33.       
  34.     RNG rng(100); // Random value generation class  
  35.   
  36.     // Set up the linearly separable part of the training data  
  37.     int nLinearSamples = (int) (FRAC_LINEAR_SEP * NTRAINING_SAMPLES);  
  38.   
  39.     // Generate random points for the class 1  
  40.     Mat trainClass = trainData.rowRange(0, nLinearSamples);  
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值