opencv hog函数调用

本文详细介绍了使用HOG特征和SVM分类器进行人脸识别的方法,包括特征提取、训练过程以及实际应用案例。通过实例代码展示了如何使用OpenCV库中的HOGDescriptor类来生成HOG特征向量,并利用SVM进行分类。此外,文章还讨论了如何保存特征向量到文件中,以及如何训练和使用已有的SVM分类器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载自 xmucyp
最终编辑 xmucyp

 I'm calling hog->compute() with default HOG parameter settings (
hog.winSize.width = 64; hog.winSize.height = 128; hog.cellSize.width = 8 =
hog.cellSize.height; hog.blockSize.width = 16; hog.blockStride.width = 8;
winStride = Size(8, 8); padding = Size(32, 32); etc. but for training, use
trainingPadding = Size(0,0) ), some excerpt of my code that could interest you:

 

std::vector<float>* calculateDescriptor(Mat img) {
vector<float>* descriptorVector = new std::vector<float>();
vector<Point> locations;
// Calculate the HOG from the image and return them in the descriptor
vector
hog.compute(img, *descriptorVector, winStride, trainingPadding,
locations);
printf("Descriptor vector size: %u", descriptorVector->size());
return descriptorVector;

}

Files: cvaux/cvhog.cpp, samples/peopledetect.cpp

All the functions usefull are given by the class HOGDescriptor. You need to train the detector using compute() and a SVM machine. Already trained classifier exist with getDefaultPeopleDetector() You can detect a people using detect() or detectMultiScale().


 仔细分析了cvhop.cpp中的compute函数,可以直接调用它来获得样本HOG,然后训练得到检测算子

1.制作样本
2.对每一张图片调用
hog.compute(img, descriptors,Size(8,8), Size(0,0));
可以生成hog descriptors,把它保存到文件中
for(int j=0;j<3780;j++)
fprintf(f,"%f,",descriptors[j]);
3.利用SVM进行训练和分类,可得到权重系数,即getDefaultPeopleDetector()函数中调用的
检测 算子 detector[]


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值