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[]