sub*_*b_o 38 opencv feature-extraction computer-vision object-recognition feature-detection
我正在尝试使用OpenCV的HoG API提取功能,但我似乎无法找到允许我这样做的API.
我想要做的是从我的所有数据集(一组正面和负面图像)中使用HoG提取特征,然后训练我自己的SVM.
我在OpenCV下偷看了HoG.cpp,但没有用.所有代码都埋没在复杂性中,需要满足不同的硬件需求(例如英特尔的IPP)
我的问题是:
到目前为止,我实际上是将一个现有的库(http://hogprocessing.altervista.org/)从Processing(Java)移植到C++,但它仍然非常慢,检测时间至少为16秒
有没有其他人成功提取HoG功能,你是如何解决它的?你有任何我可以使用的开源代码吗?
提前致谢
G45*_*453 50
您可以在opencv中使用hog类,如下所示
HOGDescriptor hog;
vector<float> ders;
vector<Point> locs;
Run Code Online (Sandbox Code Playgroud)
此功能为您计算生猪功能
hog.compute(grayImg, ders, Size(32, 32), Size(0, 0), locs);
Run Code Online (Sandbox Code Playgroud)
计算的HOG特征grayImg
存储在ders
向量中以使其成为矩阵,稍后可用于训练.
Mat Hogfeat(ders.size(), 1, CV_32FC1);
for(int i=0;i<ders.size();i++)
Hogfeat.at<float>(i,0)=ders.at(i);
Run Code Online (Sandbox Code Playgroud)
现在你的HOG功能存储在Hogfeat矩阵中.
您还可以使用对象设置窗口大小,单元格大小和块大小,hog
如下所示:
hog.blockSize = 16;
hog.cellSize = 4;
hog.blockStride = 8;
// This is for comparing the HOG features of two images without using any SVM
// (It is not an efficient way but useful when you want to compare only few or two images)
// Simple distance
// Consider you have two HOG feature vectors for two images Hogfeat1 and Hogfeat2 and those are same size.
double distance = 0;
for(int i = 0; i < Hogfeat.rows; i++)
distance += abs(Hogfeat.at<float>(i, 0) - Hogfeat.at<float>(i, 0));
if (distance < Threshold)
cout<<"Two images are of same class"<<endl;
else
cout<<"Two images are of different class"<<endl;
Run Code Online (Sandbox Code Playgroud)
希望它有用:)