OpenCV Assertion failed - convertTo

时间:2015-06-25 19:02:29

标签: c++ opencv matrix vector svm

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.

1 个答案:

答案 0 :(得分:2)

您的转化代码似乎不正确。 它应该是这样的:

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

Eyes.features的类型是什么? 似乎它应该已经是Mat1f。但是,您确定features.push_back按预期工作吗?似乎push_back需要const Mat& m

您可以从矢量中获取行矩阵:

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);