资源简介
自己训练的分类器导入进行视频行人检测 代码亲测可行,算法需要再完善 提高实时性

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//继承自CvSVM的类,因为生成setSVMDetector()中用到的检测子参数时,需要用到训练好的SVM的decision_func参数,
//但通过查看CvSVM源码可知decision_func参数是protected类型变量,无法直接访问到,只能继承之后通过函数访问
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;
}
};
int main()
{
//检测窗口(64128)块尺寸(1616)块步长(88)cell尺寸(88)直方图bin个数9
HOGDescriptor hog(Size(64 64) Size(16 16) Size(8 8) Size(8 8) 9);//HOG检测器,用来计算HOG描述子的
int DescriptorDim;//HOG描述子的维数,由图片大小、检测窗口大小、块大小、细胞单元中直方图bin个数决定
MySVM svm;//SVM分类器
svm.load(“D:/vs2013projects/cpractice/hogtrainsvm/hogtrainsvm/SVM_HOG.xml“);//从xml文件读取训练好的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 vector& detector)参数中可用的检测子
vector myDetector;
//将resultMat中的数据复制到数组myDetector中
for (int i = 0; iriptorDim; i++)
{
myDetector.push_back(resultMat.at(0 i));
}
//最后添加偏移量rho,得到检测子
myDetector.push_back(svm.get_rho());
cout << “检测子维数:“ << myDetector.size() << endl;
//设置HOGDescriptor的检测子
HOGDescriptor
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-09-12 10:06 videopeopledetect\
目录 0 2018-07-18 15:43 videopeopledetect\Debug\
文件 128512 2018-08-31 10:43 videopeopledetect\Debug\videopeopledetect.exe
文件 1477776 2018-08-31 10:43 videopeopledetect\Debug\videopeopledetect.ilk
文件 2715648 2018-08-31 10:43 videopeopledetect\Debug\videopeopledetect.pdb
目录 0 2018-09-12 10:32 videopeopledetect\videopeopledetect\
目录 0 2018-09-12 10:04 videopeopledetect\videopeopledetect\Debug\
文件 609280 2018-09-12 10:04 videopeopledetect\videopeopledetect\Debug\vc120.idb
文件 1404928 2018-09-12 10:04 videopeopledetect\videopeopledetect\Debug\vc120.pdb
目录 0 2018-09-12 10:04 videopeopledetect\videopeopledetect\Debug\videopeo.E976BEEB.tlog\
文件 11376 2018-09-12 10:04 videopeopledetect\videopeopledetect\Debug\videopeo.E976BEEB.tlog\CL.read.1.tlog
文件 502 2018-09-12 10:04 videopeopledetect\videopeopledetect\Debug\videopeo.E976BEEB.tlog\CL.write.1.tlog
文件 780 2018-09-12 10:04 videopeopledetect\videopeopledetect\Debug\videopeo.E976BEEB.tlog\cl.command.1.tlog
文件 2234 2018-08-31 10:43 videopeopledetect\videopeopledetect\Debug\videopeo.E976BEEB.tlog\li
文件 4520 2018-08-31 10:43 videopeopledetect\videopeopledetect\Debug\videopeo.E976BEEB.tlog\li
文件 640 2018-08-31 10:43 videopeopledetect\videopeopledetect\Debug\videopeo.E976BEEB.tlog\li
文件 0 2018-09-12 10:04 videopeopledetect\videopeopledetect\Debug\videopeo.E976BEEB.tlog\unsuccessfulbuild
文件 179 2018-09-12 10:04 videopeopledetect\videopeopledetect\Debug\videopeo.E976BEEB.tlog\videopeopledetect.lastbuildstate
文件 5342 2018-09-12 10:04 videopeopledetect\videopeopledetect\Debug\videopeopledetect.log
文件 20652 2018-08-31 10:43 videopeopledetect\videopeopledetect\HOGDetectorForOpenCV.txt
文件 6689 2018-09-12 10:32 videopeopledetect\videopeopledetect\videopeopledetect.cpp
文件 4107 2018-07-17 17:52 videopeopledetect\videopeopledetect\videopeopledetect.vcxproj
文件 958 2018-07-17 17:52 videopeopledetect\videopeopledetect\videopeopledetect.vcxproj.filters
文件 18481152 2018-09-12 10:06 videopeopledetect\videopeopledetect.sdf
文件 997 2018-07-16 20:48 videopeopledetect\videopeopledetect.sln
文件 24064 2018-09-12 10:06 videopeopledetect\videopeopledetect.v12.suo
相关资源
- Anti-biofilm Activity of Resveratrol and Ursol
- 基于蚁群算法优化SVM的瓦斯涌出量预
- 基于模糊聚类和SVM的瓦斯涌出量预测
- 基于CAN总线与ZigBee的瓦斯实时监测及
- SVM-Light资料,使用说明
- 果蝇算法融合SVM的开采沉陷预测模型
- BoW|Pyramid BoW+SVM进行图像分类
- 基于libsvm的图像分割代码
- 基于SVM及两类运动想象的多通道特征
- 小波包和SVM在轴承故障识别中的应用
- 林智仁教授最新版本LibSVM工具箱
- 台湾林教授的支持向量机libsvm
- 3D_HOG 代码
- 新闻分类语料
- libsvm-3.20
- 7种支持向量机SVM工具包
- A Practical Guide to Support Vector Classifica
- libSVM的代码详细解析,注释非常详细
- 台湾林志恒的LIBSVM的中文简体说明文
- SVM算法-回归拟合程序.zip
- hog特征提取,c版本代码
- 基于Grid-Search_PSO优化SVM回归预测矿井
- 新冒落带高度算法FOA-SVM预计模型
- 官方最新版本libsvm-3.23
- 基于PCA和SVM的个性化睡眠分期研究
- 基于svm四种工具箱
- 自然语言处理之文本主题判别
- ServletContextListener完成在线人数统计和
- HOG+SVM实现数字识别
- 人车分类识别 HOG特征+KNN分类器
评论
共有 条评论