资源简介
我编写的一个SVM分类+任意折交叉验证的代码,并可以按照规定的c和gamma值输出识别率,是一个不错的程序,可以解决和多问题,使用非常方便,只需要改几个想用的参数就可以,由于我使用的是VS3013和OPEMCV和众多数不同,只传了一个cpp文件上,只要导入新建工程中,并配置好opencv即可,详细过程写在程序的main函数中,请大家多多指教!!
代码片段和文件信息
// SVMclassification.cpp : 定义控制台应用程序的入口点。
//
#include “stdafx.h“
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define cvstart 1.0 //c开始值
#define cvend 30.0 //c 结束值
#define cvstep 1.0// c的增长步长
#define gammavstart 0.5 // gamma 开始值
#define gammavend 30 // gamma 结束值
#define gammavstep 0.5 // gamma 增长步长
using namespace std;
using namespace cv;
// { LINEAR = 0 POLY = 1 RBF = 2 SIGMOID = 3 };
int kenel = CvSVM::LINEAR;
void splitString(vector*str_list string srcstring string splictstring)
{
std::string o_str = srcstring;
//std::vector str_list; // 存放分割后的字符串
int comma_n = 0;
do
{
std::string tmp_s = splictstring;
comma_n = o_str.find(splictstring);
if (-1 == comma_n)
{
tmp_s = o_str.substr(0 o_str.length());
str_list->push_back(tmp_s);
break;
}
tmp_s = o_str.substr(0 comma_n);
o_str.erase(0 comma_n + 1);
str_list->push_back(tmp_s);
} while (true);
}
void setDataSet(string srcpath vector *myLable vector*> *myData){
ifstream file(srcpath); // declare file stream:
string value;
while (file.good())
{
getline(file value); // read a string until next comma:
//创建
vector *str_list = new vector();
splitString(str_list value “\t“);
//标签
float lable = atof((str_list->at(0)).c_str());
myLable->push_back(lable);
//数据
vector *hangdata = new vector();
for (int i = 1; i < str_list->size(); i++){
hangdata->push_back(atof((str_list->at(i)).c_str()));
}
myData->push_back(hangdata);
delete str_list;
// cout << string(value 0 value.length()) << ““; // display value removing the first and the last character from it
}
}
vector*> *randomIndex(int zhenshu int size){
//初始化
vector*> * indexrandom = new vector*>();
vector random;
for (int i = 0; i < size; i++){
random.push_back(i);
}
//将数组打乱顺序
srand(time(NULL));
int index temp;
for (int i = 0; i < size; i++)
{
index = rand() % (size - i) + i;
if (index != i)
{
temp = random.at(i);
random.at(i) = random.at(index);
random.at(index) = temp;
}
}
//划分n等分
int mathevermath = size / zhenshu;//每份几个
for (int i = 0; i < zhenshu; i++){
int end = mathevermath*(i + 1);
if ((size - end) < mathevermath){
end = size;
}
vector* index = new vector();
for (int j = mathevermath*i; j < end; j++){
index->push_back(random.at(j));
}
indexrandom->push_back(index);
}
return indexrandom;
}
float getShibieBySVM(float c float gamma float*ceshilabe float*ceshidata const int ceshirows const int ceshiclos float*trainlabe float*traindata const int tr
- 上一篇:拍卖系统及其说明文档
- 下一篇:北京林业大学操作系统B实验
相关资源
- 人脸识别(opencv_facedetect_v4l2)
- 基于opencv的模板匹配代码
- opencv图片扫描以及校正
- SVM算法实现(源码+文档)
- opencv手部轮廓识别以及轨迹识别
- opencv2 3D标定.cpp
- 基于opencv漫水填充算法综合
- opencv激光中心线的提取
- OpenCV Computer Vision Application Programming
- 基于图割的图像分割OpenCV+MFC实现
- 识别魔方颜色
- opencv版俄罗斯方块源码
- VS2013 / MFC + OpenCV 2.4.9实现视频的播放
- 台湾林智仁开发的libsvm-3.0.1
- 粒子滤波器+目标跟踪的C++实现,VS2
- 张平OpenCV算法精讲基于python和C++教材
- 虹膜识别开源代码OSIRIS4.1基于opencv
- Sift特征点提取与匹配opencv库
- YCbCr、混合高斯以及YCbCg肤色检测模型
- 光流法代码
- OpenCV打开摄像机显示在MFC窗口工程源
- 如何在Visual StudioVS里使用libsvm工具箱
- 使用c++读取图像到二维矩阵
- 三维点云的圆柱面拟合
- SVM分类算法实验报告+C语言程序 加强
- MFC+OPENCV摄像机标定程序
- 基于特征脸的人脸识别MFC+OpenCV
- opencv图像处理MFC
- OPENCV人脸检测加角点检测并输出坐标
- FillHole.rar
评论
共有 条评论