我需要一些基于svm的分类器的帮助。我正在尝试从图像计算HOG功能并使用它们来训练svm。现在我有一个矢量<矢量>包含每个图像的要素和行的列。为了训练CvSVM,我需要一个具有这些功能的Mat矩阵。如何将矢量矢量转换为具有相同形状的Mat?
vector<vector<float>> totFeaturesVector;
for all images:
vector<float> featuresVector;
//populate featuresVector with 3780 floats...
totFeaturesVector.push_back(featuresVector);
end for.
//numCols = 3780 numRows = 6. 6 images with 3780 features each.
//Need to convert totFeaturesVector to
//Mat training_mat(overallSamples,numCols,CV_32FC1); Something like this.
答案 0 :(得分:3)
假设final_output
是6x3780 Mat
for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++)
{
final_output.at<float>(i,j) = vector[i][j];
}
}
答案 1 :(得分:0)
vector<vector<float>> totFeaturesVector;
Mat_<float> M;
for (const auto & v: totFeaturesVector)
{
Mat_<float> r(v), t=r.t(); // you need to do this
M.push_back(t); // because push_back(Mat_<float>(v).t()) does not work
}