0

我需要一些关于基于 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. 
4

2 回答 2

3

假设 final_output是 6x3780Mat

for(int i = 0; i < height; i++)
{
    for(int j = 0; j < width; j++)
    {
        final_output.at<float>(i,j) = vector[i][j];
    }
}
于 2013-03-05T16:01:19.170 回答
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
}
于 2015-03-23T17:39:00.977 回答