0
votes

I need some help with my svm-based classifier. I am trying to compute HOG features from images and use them to train an svm. Right now I have a vector< vector > with columns containing features and rows for each image. In order to train CvSVM I need a Mat matrix with the features. How can I convert the vector of vectors into a Mat with the same shape?

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. 
2
Vector of vector of what? A numeric value? - Niko
(a) How to enumerate your vector<vector<>> + (b) How to populate a Mat matrix of features = (c) How to turn one into another. So what have you tried? - WhozCraig
Sorry for the vague question. I have a vector<vector<float>> with 6 rows and 3780 columns. I need to convert that into a Mat. I have tried different constructors, but I cant seem to get it right. Any ideas? - Jompa234

2 Answers

3
votes

Assuming final_output is a 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];
    }
}
0
votes
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
}