资源简介
HOG+SVM的行人(图片和视频)检测,在大量的训练样本的基础上得到行人检测描述子,在此基础上调用测试样本(图片及视频),检测效果不错,在机器学习训练过程花费大量时间。已测试码源可用。
代码片段和文件信息
// 3.cpp : 定义控制台应用程序的入口点。
//
#include
//#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
char filename[1024];
class MySVM : public CvSVM
{
public:
//获得SVM的决策函数中的alpha数组
double * get_alpha_vector()
{
return this->decision_func->alpha;
}
//获得SVM的决策函数中的rho参数即偏移量
float get_rho()
{
return this->decision_func->rho;
}
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void main()
{
CvCapture* cap = cvCreateFileCapture(“G:\\vsgc\\2.avi“); // 读入视频
HOGDescriptor hog(Size(64 128) Size(16 16) Size(8 8) Size(8 8) 9);//HOG检测器,用来计算HOG描述子的
int DescriptorDim;//HOG描述子的维数,由图片大小、检测窗口大小、块大小、细胞单元中直方图bin个数决定
MySVM svm;//SVM分类器
svm.load(“G:\\opencv\\11.xml“);//从xml文件读取训练好的SVM模型 //G:\\opencv\\11.xml 2400pes 12000neg hardexample 4435
//G:\\Data\\1.xml 2400pes 12000neg G:\\opencv\\1500P2000N.xml G:\\opencv\\2400P12000N.xml
//G:\\Data\\2.xml hog_svm自带生成文本
/*************************************************************************************************
线性SVM训练完成后得到的xml文件里面,有一个数组,叫做support vector,还有一个数组,叫做alpha有一个浮点数,叫做rho;
将alpha矩阵同support vector相乘,注意,alpha*supportVector将得到一个列向量。之后,再该列向量的最后添加一个元素rho。
如此,变得到了一个分类器,利用该分类器,直接替换opencv中行人检测默认的那个分类器(cv::HOGDescriptor::setSVMDetector()),
就可以利用你的训练样本训练出来的分类器进行行人检测了。
***************************************************************************************************/
DescriptorDim = svm.get_var_count();//特征向量的维数,即HOG描述子的维数
int supportVectorNum = svm.get_support_vector_count();//支持向量的个数
cout << “支持向量个数:“ << supportVectorNum << endl;
Mat alphaMat = Mat::zeros(1 supportVectorNum CV_32FC1);//alpha向量,长度等于支持向量个数
Mat supportVectorMat = Mat::zeros(supportVectorNum DescriptorDim CV_32FC1);//支持向量矩阵
Mat resultMat = Mat::zeros(1 DescriptorDim CV_32FC1);//alpha向量乘以支持向量矩阵的结果
//将支持向量的数据复制到supportVectorMat矩阵中
for (int i = 0; i {
const float * pSVData = svm.get_support_vector(i);//返回第i个支持向量的数据指针
for (int j = 0; jriptorDim; j++)
{
//cout< supportVectorMat.at(i j) = pSVData[j];
}
}
//将alpha向量的数据复制到alphaMat中
double * pAlphaData = svm.get_alpha_vector();//返回SVM的决策函数中的alpha向量
for (int i = 0; i {
alphaMat.at(0 i) = pAlphaData[i];
}
//计算-(alphaMat * supportVectorMat)结果放到resultMat中
//gemm(alphaMat supportVectorMat -1 0 1 resultMat);//不知道为什么加负号?
resultMat = -1 * alphaMat * supportVectorMat;
//得到最终的setSVMDetector(const v
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-06-11 01:40 shipinceshi\
目录 0 2017-06-11 01:37 shipinceshi\3\
文件 7893 2017-06-11 01:37 shipinceshi\3\3.cpp
文件 4647 2017-04-17 13:57 shipinceshi\3\3.vcxproj
文件 1308 2017-04-17 11:31 shipinceshi\3\3.vcxproj.filters
文件 24102 2017-04-17 14:22 shipinceshi\3\3.zip
文件 44073 2017-06-11 01:40 shipinceshi\3\HOGDetectorForOpenCV.txt
文件 1468 2017-04-17 11:31 shipinceshi\3\ReadMe.txt
文件 23380170 2017-06-11 01:11 shipinceshi\3\out -1.avi
文件 22864278 2017-06-11 01:40 shipinceshi\3\out.avi
文件 207 2017-04-17 11:31 shipinceshi\3\stdafx.cpp
文件 267 2017-04-17 13:03 shipinceshi\3\stdafx.h
文件 236 2017-04-17 11:31 shipinceshi\3\targetver.h
目录 0 2017-06-11 01:26 shipinceshi\3\x64\
目录 0 2017-06-11 01:37 shipinceshi\3\x64\Debug\
文件 1634 2017-06-11 01:37 shipinceshi\3\x64\Debug\3.log
文件 907008 2017-06-11 01:37 shipinceshi\3\x64\Debug\3.obj
文件 3997696 2017-06-11 01:34 shipinceshi\3\x64\Debug\3.pch
目录 0 2017-06-11 01:37 shipinceshi\3\x64\Debug\3.tlog\
文件 151 2017-06-11 01:37 shipinceshi\3\x64\Debug\3.tlog\3.lastbuildstate
文件 67642 2017-06-11 01:37 shipinceshi\3\x64\Debug\3.tlog\CL.read.1.tlog
文件 2048 2017-06-11 01:37 shipinceshi\3\x64\Debug\3.tlog\CL.write.1.tlog
文件 6188 2017-06-11 01:37 shipinceshi\3\x64\Debug\3.tlog\cl.command.1.tlog
文件 12592 2017-06-11 01:37 shipinceshi\3\x64\Debug\3.tlog\li
文件 14966 2017-06-11 01:37 shipinceshi\3\x64\Debug\3.tlog\li
文件 1106 2017-06-11 01:37 shipinceshi\3\x64\Debug\3.tlog\li
文件 10084 2017-06-11 01:34 shipinceshi\3\x64\Debug\stdafx.obj
文件 1035264 2017-06-11 01:37 shipinceshi\3\x64\Debug\vc120.idb
文件 1863680 2017-06-11 01:37 shipinceshi\3\x64\Debug\vc120.pdb
文件 16973824 2017-06-11 01:40 shipinceshi\3.sdf
文件 1143 2017-04-17 12:34 shipinceshi\3.sln
............此处省略10个文件信息
相关资源
- 机器学习课件
- 贝叶斯方法 概率编程与贝叶斯推断
- 李航-统计学方法-书签-目录
- 机器学习中的特征工程FeatureEngineeri
- 数字0到9和英文大小写字母手写识别训
-
multi-ob
jective machine learning.pdf - 《贝叶斯数据分析(英文导读版·原书
- Handwritten_digit_recognition.zip
- Horn R A Johnson C R Matrix Analysis (CUP 19
- Hands-On Machine Learning with Scikit-Learn Ke
- The Nature of Statistical Learning Theory - Va
- 回归方法和机器学习方法以及R代码实
- Time series analysis forecasting and control 5
- Deep Learning medical image analysis英文高清
- PRML中文版_模式识别与机器学习.pdf
- 概率统计超入门
- arff数据集全集weka机器学习必备
- 斯坦福大学机器学习课程讲义cs229-a
- 李航《统计学习方法》带书签高清完
- Web安全之机器学习全套.rar
- fashion-mnist数据集
- 机器学习:贝叶斯和优化方法英文文
- 机器学习:实用案例解析R语言
- coursera斯坦福Andrew Ng机器学习编程作业
- 机器学习导论
- 机器学习圣经_ISL_ESL.rar
- 2019年AI高赞新书《可解释的机器学习
- The Hundred-Page Machine Learning Book.pdf
- 最新版李航统计学习方法
- 人脸分析识别系统笑或不笑
评论
共有 条评论