基于HOG和SVM的行人检测 matlab平台
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-06-30 15:36 SVM_Train_Predict_HOG2
目录 0 2015-06-30 15:36 SVM_Train_Predict_HOG2SVM_Train_Predict_HOG
目录 0 2015-06-30 15:36 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGDebug
文件 144896 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.exe
文件 1115176 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.ilk
文件 1960960 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.pdb
目录 0 2015-06-30 15:36 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG
文件 174277 2013-10-22 16:53 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG 0000.jpg
文件 788547 2013-10-21 21:44 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG1.png
文件 813015 2013-10-21 21:47 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG2.png
文件 90689 2007-01-10 01:37 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG2007_000423.jpg
文件 818604 2013-10-21 21:48 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG3.png
文件 1610478 2013-10-21 21:48 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG4.png
文件 911894 2013-10-21 21:49 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG5.png
目录 0 2015-06-30 15:36 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebug
文件 27996 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugCL.read.1.tlog
文件 968 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugCL.write.1.tlog
文件 406 2013-11-07 15:55 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.exe.embed.manifest
文件 472 2014-11-24 11:22 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.exe.embed.manifest.res
文件 381 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.exe.intermediate.manifest
文件 78 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.lastbuildstate
文件 3508 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.log
文件 477476 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.obj
文件 707 2014-11-24 12:42 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.vcxprojResolveAssemblyReference.cache
文件 0 2014-11-24 11:22 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.write.1.tlog
文件 232 2013-11-07 15:55 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG_manifest.rc
文件 1542 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugcl.command.1.tlog
文件 2 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebuglink-cvtres.read.1.tlog
文件 2 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebuglink-cvtres.write.1.tlog
文件 2 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebuglink.10128-cvtres.read.1.tlog
文件 2 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebuglink.10128-cvtres.write.1.tlog
............此处省略120个文件信息
#include
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
#define PosSamNO 2400 //正样本个数
#define NegSamNO 12000 //负样本个数
#define TRAIN false //是否进行训练true表示重新训练,false表示读取xml文件中的SVM模型
#define CENTRAL_CROP true //true:训练时,对96*160的INRIA正样本图片剪裁出中间的64*128大小人体
//HardExample:负样本个数。如果HardExampleNO大于0,表示处理完初始负样本集后,继续处理HardExample负样本集。
//不使用HardExample时必须设置为0,因为特征向量矩阵和特征类别矩阵的维数初始化时用到这个值
#define HardExampleNO 0
//继承自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(64128)Size(1616)Size(88)Size(88)9);//HOG检测器,用来计算HOG描述子的
int DescriptorDim;//HOG描述子的维数,由图片大小、检测窗口大小、块大小、细胞单元中直方图bin个数决定
MySVM svm;//SVM分类器
//若TRAIN为true,重新训练分类器
if(TRAIN)
{
string ImgName;//图片名(绝对路径)
ifstream finPos(“INRIAPerson96X160PosList.txt“);//正样本图片的文件名列表
//ifstream finPos(“PersonFromVOC2012List.txt“);//正样本图片的文件名列表
ifstream finNeg(“NoPersonFromINRIAList.txt“);//负样本图片的文件名列表
Mat sampleFeatureMat;//所有训练样本的特征向量组成的矩阵,行数等于所有样本的个数,列数等于HOG描述子维数
Mat sampleLabelMat;//训练样本的类别向量,行数等于所有样本的个数,列数等于1;1表示有人,-1表示无人
//依次读取正样本图片,生成HOG描述子
for(int num=0; num {
cout<<“处理:“< //ImgName = “D:\DataSet\PersonFromVOC2012\“ + ImgName;//加上正样本的路径名
ImgName = “E:\运动目标检测\INRIAPerson\96X160H96\Train\pos\“ + ImgName;//加上正样本的路径名
Mat src = imread(ImgName);//读取图片
if(CENTRAL_CROP)
src = src(Rect(161664128));//将96*160的INRIA正样本图片剪裁为64*128,即剪去上下左右各16个像素
//resize(srcsrcSize(64128));
vector descriptors;//HOG描述子向量
hog.compute(srcdescriptorsSize(88));//计算HOG描述子,检测窗口移动步长(88)
//
cout<<“描述子维数:“<riptors.size()<
//处理第一个样本时初始化特征向量矩阵和类别矩阵,因为只有知道了特征向量的维数才能初始化特征向量矩阵
if( 0 == num )
{
DescriptorDim = descriptors.size();//HOG描述子的维数
//初始化所有训练样本的特征向量组成的矩阵,行数等于所有样本的个数,列数等于HOG描述子维数sampleFeatureMat
sampleFeatureMat = Mat::zeros(PosSamNO+NegSamNO+HardExampleNO DescriptorDim CV_32FC1);
//初始化训练样本的类别向量,行数等于所有样本的个数,列数等于1;1表示有人,0表示无人
sampleLabelMat = Mat::zeros(PosSamNO+NegSamNO+HardExampleNO 1 CV_32FC1);
}
//将计算好的HOG描述子复制到样本特征矩阵sampleFeatureMat
for(int i=0; iriptorDim; i++)
sampleFeatureMat.at(numi) = descriptors[i];//第num个样本的特征向量中的第i个元素
sampleLabelMat.at(num0) =
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-06-30 15:36 SVM_Train_Predict_HOG2
目录 0 2015-06-30 15:36 SVM_Train_Predict_HOG2SVM_Train_Predict_HOG
目录 0 2015-06-30 15:36 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGDebug
文件 144896 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.exe
文件 1115176 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.ilk
文件 1960960 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.pdb
目录 0 2015-06-30 15:36 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG
文件 174277 2013-10-22 16:53 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG 0000.jpg
文件 788547 2013-10-21 21:44 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG1.png
文件 813015 2013-10-21 21:47 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG2.png
文件 90689 2007-01-10 01:37 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG2007_000423.jpg
文件 818604 2013-10-21 21:48 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG3.png
文件 1610478 2013-10-21 21:48 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG4.png
文件 911894 2013-10-21 21:49 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOG5.png
目录 0 2015-06-30 15:36 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebug
文件 27996 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugCL.read.1.tlog
文件 968 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugCL.write.1.tlog
文件 406 2013-11-07 15:55 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.exe.em
文件 472 2014-11-24 11:22 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.exe.em
文件 381 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.exe.intermediate.manifest
文件 78 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.lastbuildstate
文件 3508 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.log
文件 477476 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.obj
文件 707 2014-11-24 12:42 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.vcxprojResolveAssemblyReference.cache
文件 0 2014-11-24 11:22 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG.write.1.tlog
文件 232 2013-11-07 15:55 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugSVM_Train_Predict_HOG_manifest.rc
文件 1542 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugcl.command.1.tlog
文件 2 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugli
文件 2 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugli
文件 2 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugli
文件 2 2014-11-24 16:06 SVM_Train_Predict_HOG2SVM_Train_Predict_HOGSVM_Train_Predict_HOGDebugli
............此处省略120个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)