0
votes

I have a matrix of labels for training SVM of size (1 x 5).. 5 labels for 5 image.

Now, the problem is that, the data matrix with training data is of size (1 x 65000). Infact this matrix has to be of size (5 x 13000); that is 5 columns (image) of 13000 rows.

I tried reshaping but it didnt work. Can i get some help how to change the matrix size.

Thank you

1
How do you init your Mat ? - Poko

1 Answers

1
votes

The simplest thing to do here would be to create a new matrix and copy the elements over one at a time. I'm not sure what the structure of your matrix is, but let's say the first training example corresponds to what you currently have in entries 1-5 of your incorrectly-shaped matrix.

cv::Mat training_data = new cv::Mat(13000, 5, CV_32F);
for (unsigned int row = 0; row < training_data.rows; ++row)
{
    for (unsigned int col = 0; col < training_data.cols; ++col)
    {
        training_data.at<float>(row, col) = old_training_data.at<float>(1, (training_data.cols * row) + col);
    }
}

Then release the old training data matrix, and you have a brand new (correctly shaped!) matrix.