如何在OPENCV 2.4.13中导入训练有素的SVM检测器
How to import a trained SVM detector in OpenCV 2.4.13
所以我遵循本指南来训练自己的行人猪探测器。https://github.com/dahoc/trainhog/wiki/trainhog-tutorial
,它成功地生成了4个文件。
- cvhogclassifier.yaml
- disciptorvector.dat
- 功能.dat
- svmlightmodel.dat
有人知道如何将DexcriptorVector.dat文件加载为向量吗?我尝试过但失败了。
vector<float> detector;
std::ifstream file;
file.open("descriptorvector.dat");
file >> detector;
file.close();
这是我最终想使用的东西。
gpu::HOGDescriptor hog(Size(64, 128), Size(16, 16), Size(8, 8), Size(8, 8),9);
hog.setSVMDetector(detector);
预先感谢您!
如果您已经训练了SVM,则可以将权重和截距保存在TXT文件中,然后将其加载到数组/矢量中。然后,您将使用如下:
std::vector<float> descriptorsValues; //A vector to store the computed HoG values
std::vector<cv::Point> locations;
hog.compute(image, descriptorsValues, cv::Size(0, 0), cv::Size(0, 0), locations);
double res = 0;
for (int i = 0; i < svmDimension - 1; i++)
{
res += w[i] * descriptorsValues.at(i);
}
res = res + w[svmDimension - 1];
return res;
其中 svmDimension
是包含SVM权重的数组/向量,然后是SVM截距,而res
是SVM响应
您可以读取文件并将每个值推回float
的数组,因此首先声明它:
vector<float> myDescriptorVector;
然后推动每个值:
ifstream infile ("yourFile.dat".c_str());
float number;
while (infile >> number)
myDescriptorVector.push_back(number);
return myDescriptorVector;
最终使用猪的标准初始化,然后将矢量传递给SVM检测器,如您已经猜到的:
hog.setSVMDetector(myDescriptorVector);
相关文章:
- 尝试导入pybind-opencv模块时出现libgtk错误
- 导入库可以跨dll版本工作吗
- 建议在运行时将带有类实例的列表从c++导入qml
- 导入/导出变量时出错
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 将QT项目导入Visual Studio 2019会给我带来很多LNK2001错误
- 是否可以将函数导入命名空间,但不能导出它?
- 如何将 CLion C++ 项目导入 Visual Studio?
- Python 3.8 不能与 Pybind11 一起导入 [Windows]
- 无法将标准库导入本机 android 项目中的头文件
- 尝试了解在导入的静态方法上使用删除方法时的错误
- 在 python 模块中导入子模块时PyImport_Import失败
- 将 C# DLL 导入 C++ 以用于 JNI
- 使用 QSslCertificate 在 Qt 中正确导入 pkcs12
- 在从Qt调用的Python脚本中导入OpenCV崩溃
- 编译boost_python扩展无法在 python 2.7 中导入
- 如何在安卓工作室中将c ++头文件从一个文件夹导入到另一个文件夹?
- Dll在同一解决方案中从 c# 项目导入到 c++ 项目
- C++20 使用 Visual Studio 编译模块:不编译或导入 ixx 文件
- 如何在OPENCV 2.4.13中导入训练有素的SVM检测器