如何在OpenCV 2.4.13中导入训练有素的SVM检测器 [英] How to import a trained SVM detector in OpenCV 2.4.13
问题描述
因此,我已经按照本指南培训了自己的行人HOG检测器. https://github.com/DaHoC/trainHOG/wiki/trainHOG-Tutorial
So I have followed this guide to train my own pedestrian HOG detector. https://github.com/DaHoC/trainHOG/wiki/trainHOG-Tutorial
成功生成了4个文件.
And it was successful with 4 files generated.
- cvHOGClassifier.yaml
- descriptorvector.dat
- features.dat
- svmlightmodel.dat
有人知道如何将描述符vector.dat文件作为矢量加载吗? 我已经尝试过了,但是失败了.
Does anyone know how to load the descriptorvector.dat file as a vector? I've tried this but failed.
vector<float> detector;
std::ifstream file;
file.open("descriptorvector.dat");
file >> detector;
file.close();
这是我最终要使用的东西.
This is something I would like to use eventually.
gpu::HOGDescriptor hog(Size(64, 128), Size(16, 16), Size(8, 8), Size(8, 8),9);
hog.setSVMDetector(detector);
先谢谢您!
推荐答案
您可以读取文件并将每个值都推回float
数组,因此首先声明它:
You can read the file and push every value back to an array of float
, so first declare it:
vector<float> myDescriptorVector;
然后推送每个值:
ifstream infile ("yourFile.dat".c_str());
float number;
while (infile >> number)
myDescriptorVector.push_back(number);
return myDescriptorVector;
最后,对HOG使用标准初始化,然后将向量传递到SVM检测器,就像您已经猜到的那样:
Finally use the standard initialization for the HOG and pass the vector to the SVM detector as you already guessed:
hog.setSVMDetector(myDescriptorVector);
这篇关于如何在OpenCV 2.4.13中导入训练有素的SVM检测器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!