自己训练的分类器导入进行视频行人检测 代码亲测可行,算法需要再完善 提高实时性
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-09-12 10:06 videopeopledetect
目录 0 2018-07-18 15:43 videopeopledetectDebug
文件 128512 2018-08-31 10:43 videopeopledetectDebugvideopeopledetect.exe
文件 1477776 2018-08-31 10:43 videopeopledetectDebugvideopeopledetect.ilk
文件 2715648 2018-08-31 10:43 videopeopledetectDebugvideopeopledetect.pdb
目录 0 2018-09-12 10:32 videopeopledetectvideopeopledetect
目录 0 2018-09-12 10:04 videopeopledetectvideopeopledetectDebug
文件 609280 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvc120.idb
文件 1404928 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvc120.pdb
目录 0 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlog
文件 11376 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlogCL.read.1.tlog
文件 502 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlogCL.write.1.tlog
文件 780 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlogcl.command.1.tlog
文件 2234 2018-08-31 10:43 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tloglink.command.1.tlog
文件 4520 2018-08-31 10:43 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tloglink.read.1.tlog
文件 640 2018-08-31 10:43 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tloglink.write.1.tlog
文件 0 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlogunsuccessfulbuild
文件 179 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlogvideopeopledetect.lastbuildstate
文件 5342 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvideopeopledetect.log
文件 20652 2018-08-31 10:43 videopeopledetectvideopeopledetectHOGDetectorForOpenCV.txt
文件 6689 2018-09-12 10:32 videopeopledetectvideopeopledetectvideopeopledetect.cpp
文件 4107 2018-07-17 17:52 videopeopledetectvideopeopledetectvideopeopledetect.vcxproj
文件 958 2018-07-17 17:52 videopeopledetectvideopeopledetectvideopeopledetect.vcxproj.filters
文件 18481152 2018-09-12 10:06 videopeopledetectvideopeopledetect.sdf
文件 997 2018-07-16 20:48 videopeopledetectvideopeopledetect.sln
文件 24064 2018-09-12 10:06 videopeopledetectvideopeopledetect.v12.suo
#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 videopeopledetectDebug
文件 128512 2018-08-31 10:43 videopeopledetectDebugvideopeopledetect.exe
文件 1477776 2018-08-31 10:43 videopeopledetectDebugvideopeopledetect.ilk
文件 2715648 2018-08-31 10:43 videopeopledetectDebugvideopeopledetect.pdb
目录 0 2018-09-12 10:32 videopeopledetectvideopeopledetect
目录 0 2018-09-12 10:04 videopeopledetectvideopeopledetectDebug
文件 609280 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvc120.idb
文件 1404928 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvc120.pdb
目录 0 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlog
文件 11376 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlogCL.read.1.tlog
文件 502 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlogCL.write.1.tlog
文件 780 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlogcl.command.1.tlog
文件 2234 2018-08-31 10:43 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlogli
文件 4520 2018-08-31 10:43 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlogli
文件 640 2018-08-31 10:43 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlogli
文件 0 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlogunsuccessfulbuild
文件 179 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvideopeo.E976BEEB.tlogvideopeopledetect.lastbuildstate
文件 5342 2018-09-12 10:04 videopeopledetectvideopeopledetectDebugvideopeopledetect.log
文件 20652 2018-08-31 10:43 videopeopledetectvideopeopledetectHOGDetectorForOpenCV.txt
文件 6689 2018-09-12 10:32 videopeopledetectvideopeopledetectvideopeopledetect.cpp
文件 4107 2018-07-17 17:52 videopeopledetectvideopeopledetectvideopeopledetect.vcxproj
文件 958 2018-07-17 17:52 videopeopledetectvideopeopledetectvideopeopledetect.vcxproj.filters
文件 18481152 2018-09-12 10:06 videopeopledetectvideopeopledetect.sdf
文件 997 2018-07-16 20:48 videopeopledetectvideopeopledetect.sln
文件 24064 2018-09-12 10:06 videopeopledetectvideopeopledetect.v12.suo
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)