vicR
vicR

Reputation: 819

OpenCV Assertion failed - convertTo

I'm trying to convert my matrix into CV_32FC1 to train my SVM.I always get the error msg:

OpenCV Error: Assertion failed (func != 0) in convertTo, file /opt/opencv/modules/core/src/convert.cpp, line 1115
/eropt/opencv/modules/core/src/convert.cpp:1115: error: (-215) func != 0 in function convtTo

Basically I'm trying to

Mat eyes_train_data = Mat::zeros(Eyes.features.size(), CV_32FC1);
Eyes.features.copyTo(eyes_train_data);
eyes_train_data.convertTo(eyes_train_data, CV_32FC1);

I already tried to get the depth() of the matrix which returns 7. I'm not sure what that means. the Eyes.features matrix is a (or should be) a floating-point matrix

to get the Eyes.features i use a gotHogFeatures-Method with

    vector<float> descriptorsValues;
    vector<Point> location;
    for( Mat patch : patches) {
      hog.compute( patch, descriptorsValues, Size(0,0), Size(0,0),   location);
        features.push_back(descriptorsValues); 
 }

descriptorValues represents a row vector and features should than look like:

features: 
{
descriptorValues0
descriptorValues1
...
}

thanks for any help.

Upvotes: 0

Views: 992

Answers (1)

Miki
Miki

Reputation: 41765

Your conversion code doesn't seems right. It should be something like:

Mat eyes_train_data;
eyes_train_data.convertTo(eyes_train_data, CV_32FC1);

What's the type of Eyes.features? It seems that it should be already a Mat1f. However, are you sure that features.push_back works as expected? It seems that push_back needs a const Mat& m.

You can get a row matrix from a vector:

Mat1f m;
vector<float> v1 = {1.f, 1.5f, 2.1f};
vector<float> v2 = {3.f, 3.5f, 4.1f};

Mat temp1(Mat1f(v1).t());
Mat temp2(Mat1f(v2).t());

m.push_back(temp1);
m.push_back(temp2);

Upvotes: 2

Related Questions