1. 程式人生 > >C++ Opencv——Hog+SVM

C++ Opencv——Hog+SVM

思路: 

// HOG描述子向量
std::vector<float> descriptors;
cv::HOGDescriptor hog(cv::Size(48, 48), cv::Size(16, 16), cv::Size(8, 8), cv::Size(8, 8), 9);
hog.compute(src, descriptors, cv::Size(8, 8));
int DescriptorDim = descriptors.size();
// SVM 樣本+標籤
int num;
Mat sampleFeatureMat = cv::Mat::zeros(num, DescriptorDim, CV_32FC1);
int i, j;//i為樣本序列,j為樣本特徵值
sampleFeatureMat.at<float>(i, j) = descriptors[j];
Mat sampleLabelMat;
int label;
sampleLabelMat.at<float>(i, 0) = label;