训练SVM分类器 VS2013 C++


程序一:修改文件名的程序,可以用来批处理文件将文件名修改为数字命名并写到文本文件中 程序二:SVM训练程序。
资源截图
代码片段和文件信息
#include “ChangeSamplePath.h“
#include 
#include 

int ChangeSamplePath::_name_length = 8;

ChangeSamplePath::ChangeSamplePath()
{
}

ChangeSamplePath::ChangeSamplePath(std::string path) :_main_path(path)
{
initial();
}

ChangeSamplePath::~ChangeSamplePath()
{
_neg_out.close();
_pos_out.close();
}

inline void ChangeSamplePath::initial()
{
_neg_path = _main_path + “\neg“;
_pos_path = _main_path + “\pos“;
_neg_txt_path = _main_path + “\neg.txt“;
_pos_txt_path = _main_path + “\pos.txt“;

_neg_out.open(_neg_txt_path.c_str() std::ios_base::out);
_ASSERT(_neg_out.is_open());
_pos_out.open(_pos_txt_path.c_str() std::ios_base::out);
if (!_pos_out.is_open()) _neg_out.close();
_ASSERT(_pos_out.is_open());
}

void ChangeSamplePath::setPath(std::string path)
{
_main_path = path;
initial();
}

void ChangeSamplePath::changeFileName(std::ofstream& out std::string path)
{
long handler;
_finddata_t file_finder;

std::string file_name = path + “\*.*“;
_ASSERT((handler = _findfirst(file_name.c_str() &file_finder)) != -1);

do{
if (file_finder.attrib & _A_ARCH)
{
std::string old_file_name(file_finder.name);
int dot_index = old_file_name.find(‘.‘);
std::string new_file_name = old_file_name.substr(0 dot_index) + “temp“ + old_file_name.substr(dot_index old_file_name.length());
old_file_name = path + “\“ + old_file_name;
new_file_name = path + “\“ + new_file_name;
rename(old_file_name.c_str() new_file_name.c_str());
}
} while (_findnext(handler &file_finder) == 0);

_findclose(handler);
_ASSERT((handler = _findfirst(file_name.c_str() &file_finder)) != -1);
int count = 0;
do{
if (file_finder.attrib & _A_ARCH)
{
count++;
std::string old_file_name(file_finder.name);
int dot_index = old_file_name.find(‘.‘);
std::string new_file_name = generateName(count) + old_file_name.substr(dot_index old_file_name.length());
old_file_name = path + “\“ + old_file_name;
new_file_name = path + “\“ + new_file_name;
rename(old_file_name.c_str() new_file_name.c_str());
out << new_file_name << std::endl;
}
} while (_findnext(handler &file_finder) == 0);

_findclose(handler);

}

void ChangeSamplePath::doChange()
{
//neg_samples:
changeFileName(_neg_out _neg_path);
//pos_samples:
changeFileName(_pos_out _pos_path);
}

std::string ChangeSamplePath::generateName(int num)
{
char* name = new char[_name_length + 1];
int count = 0; 
do{
count++;
name[_name_length - count] = num % 10 + ‘0‘;
num /= 10;
} while (num != 0);

for (int i = 0; i < _name_length - count; ++i)
{
name[i] = ‘0‘;
}
name[_name_length] = ‘‘;
std::string new_name(name);
delete name;
return new_name;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-04-17 16:45  训练SVM分类器
     目录           0  2018-04-17 16:45  训练SVM分类器修改文件名程序
     目录           0  2018-04-17 16:49  训练SVM分类器修改文件名程序ChangeSamplePath
     目录           0  2018-04-17 16:49  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePath
     文件        2812  2018-04-17 16:22  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathChangeSamplePath.cpp
     文件        1262  2018-04-17 16:49  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathChangeSamplePath.h
     文件        4221  2018-04-17 14:26  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathChangeSamplePath.vcxproj
     文件        1173  2018-04-17 14:26  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathChangeSamplePath.vcxproj.filters
     目录           0  2018-04-17 16:45  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebug
     文件        1142  2018-04-17 16:17  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebugChangeSamplePath.Build.CppClean.log
     文件        1501  2018-04-17 16:23  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebugChangeSamplePath.log
     文件      353131  2018-04-17 16:23  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebugChangeSamplePath.obj
     目录           0  2018-04-17 16:45  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebugChangeSamplePath.tlog
     文件         174  2018-04-17 16:23  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebugChangeSamplePath.tlogChangeSamplePath.lastbuildstate
     文件        1442  2018-04-17 16:23  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebugChangeSamplePath.tlogcl.command.1.tlog
     文件       13764  2018-04-17 16:23  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebugChangeSamplePath.tlogCL.read.1.tlog
     文件        1822  2018-04-17 16:23  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebugChangeSamplePath.tlogCL.write.1.tlog
     文件        1472  2018-04-17 16:23  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebugChangeSamplePath.tloglink.command.1.tlog
     文件        3002  2018-04-17 16:23  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebugChangeSamplePath.tloglink.read.1.tlog
     文件         730  2018-04-17 16:23  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebugChangeSamplePath.tloglink.write.1.tlog
     文件      355328  2018-04-17 16:23  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebugvc120.idb
     文件      372736  2018-04-17 16:23  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebugvc120.pdb
     文件      139462  2018-04-17 16:17  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePathDebug源.obj
     文件         192  2018-04-17 14:57  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePath源.cpp
     文件     7340032  2018-04-17 16:49  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePath.sdf
     文件         994  2018-04-17 11:39  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePath.sln
     文件       31744  2018-04-17 16:49  训练SVM分类器修改文件名程序ChangeSamplePathChangeSamplePath.v12.suo
     目录           0  2018-04-17 16:45  训练SVM分类器修改文件名程序ChangeSamplePathDebug
     文件      115200  2018-04-17 16:23  训练SVM分类器修改文件名程序ChangeSamplePathDebugChangeSamplePath.exe
     文件      646104  2018-04-17 16:23  训练SVM分类器修改文件名程序ChangeSamplePathDebugChangeSamplePath.ilk
     文件      871424  2018-04-17 16:23  训练SVM分类器修改文件名程序ChangeSamplePathDebugChangeSamplePath.pdb
............此处省略31个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)