OpenCV的SVM用法
在OpenCV當中,SVM是作為一個類來定義介面的,其定義略顯複雜。不過,如果你對libSVM比較瞭解,就會發現,OpenCV的SVM介面與libSVM的介面非常接近。下面,我還利用前面介紹libSVM用法時的資料,通過一個簡單的例子程式來介紹OpenCV的SVM模組函式的用法。
// OpencvSVM.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "cv.h"
#include "ml.h"
#include "iostream"
using namespace std;
double inputArr[10][13] =
{
1,0.708333,1,1,-0.320755,-0.105023,-1,1,-0.419847,-1,-0.225806,0,1,
-1,0.583333,-1,0.333333,-0.603774,1,-1,1,0.358779,-1,-0.483871,0,-1,
1,0.166667,1,-0.333333,-0.433962,-0.383562,-1,-1,0.0687023,-1,-0.903226,-1,-1,
-1,0.458333,1,1,-0.358491,-0.374429,-1,-1,-0.480916,1,-0.935484,0,-0.333333,
-1,0.875,-1,-0.333333,-0.509434,-0.347032,-1,1,-0.236641,1,-0.935484,-1,-0.333333,
-1,0.5,1,1,-0.509434,-0.767123,-1,-1,0.0534351,-1,-0.870968,-1,-1,
1,0.125,1,0.333333,-0.320755,-0.406393,1,1,0.0839695,1,-0.806452,0,-0.333333,
1,0.25,1,1,-0.698113,-0.484018,-1,1,0.0839695,1,-0.612903,0,-0.333333,
1,0.291667,1,1,-0.132075,-0.237443,-1,1,0.51145,-1,-0.612903,0,0.333333,
1,0.416667,-1,1,0.0566038,0.283105,-1,1,0.267176,-1,0.290323,0,1
};
double testArr[]=
{
0.25,1,1,-0.226415,-0.506849,-1,-1,0.374046,-1,-0.83871,0,-1
};
int _tmain(int argc, _TCHAR* argv[])
{
CvSVM svm;
CvSVMParams param;
param.svm_type = 100;
param.kernel_type = 1;
param.degree = 4;
param.gamma = 4;
param.coef0 = 1;
CvMat *dataMat = cvCreateMat(10, 12, CV_32FC1);
CvMat *labelMat = cvCreateMat(10, 1, CV_32SC1);
for (int i=0; i<10; i++)
{
for (int j=0; j<12; j++)
{
cvSetReal2D(dataMat, i, j, inputArr[i][j+1]);
}
cvSetReal2D(labelMat, i, 0, inputArr[i][0]);
}
svm.train(dataMat, labelMat, NULL, NULL, param);
svm.save("c:/svmResult.txt");
CvMat *testMat = cvCreateMat(1, 12, CV_32FC1);
for (int i=0; i<12; i++)
{
cvSetReal2D(testMat, 0, i, testArr[i]);
}
float flag = 0;
flag = svm.predict(testMat);
cout<<"testMat, flag = "<<flag<<endl;
system("pause");
cvReleaseMat(&dataMat);
cvReleaseMat(&labelMat);
cvReleaseMat(&testMat);
return 0;
}
相關文章
- opencv SVM的使用OpenCV
- opencv中SVMOpenCV
- OpenCV 與 SVMOpenCV
- opencv SVM 使用OpenCV
- opencv + SVM 程式碼OpenCV
- opencv svm分類OpenCV
- 學習OpenCV——SVMOpenCV
- opencv SVM分類DemoOpenCV
- opencv中svm原始碼OpenCV原始碼
- OpenCV進階---介紹SVMOpenCV
- OpenCV中使用SVM簡介OpenCV
- opencv中的SVM影像分類(二)OpenCV
- opencv中的SVM影像分類(一)OpenCV
- OpenCV中的SVM引數優化OpenCV優化
- 學習SVM(一) SVM模型訓練與分類的OpenCV實現模型OpenCV
- OPENCV SVM介紹和自帶例子OpenCV
- Opencv 用SVM訓練檢測器OpenCV
- opencv python 基於SVM的手寫體識別OpenCVPython
- SVM多分類器的實現(Opencv3,C++)OpenCVC++
- OpenCV筆記(3)實現支援向量機(SVM)OpenCV筆記
- 學習Opencv2.4.9(四)---SVM支援向量機OpenCV
- 我的OpenCV學習筆記(六):使用支援向量機(SVM)OpenCV筆記
- Opencv中SVM樣本訓練、歸類流程及實現OpenCV
- 機器學習(3),opencv4.0中SVM各個引數的意義,設定機器學習OpenCV
- OpenCV findContours 與 drawContours 用法OpenCV
- 【opencv3】 svm實現手寫體與人臉識別OpenCV
- opencv呼叫cv2.dnn_DetectionModel 用法OpenCVDNN
- SVM
- 學習SVM(五)理解線性SVM的鬆弛因子
- 學習SVM(四) 理解SVM中的支援向量(Support Vector)
- opencv查詢輪廓---cvFindContours && cvDrawCountours 用法及例子OpenCV
- SVM原理
- 【Svm機器學習篇】Opencv3.4.1與C++實現對分類問題的訓練與預測】機器學習OpenCVC++
- Python機器學習筆記:SVM(1)——SVM概述Python機器學習筆記
- Python機器學習筆記:SVM(3)——證明SVMPython機器學習筆記
- 支援向量機(Support Vector Machine,SVM)—— 線性SVMMac
- svm的smo演算法演算法
- OpenCL中的SVM使用案例