简体   繁体   English

OpenCV断言失败-convertTo

[英]OpenCV Assertion failed - convertTo

I'm trying to convert my matrix into CV_32FC1 to train my SVM.I always get the error msg: 我正在尝试将矩阵转换为CV_32FC1以训练我的SVM。我总是收到错误消息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 . 我已经尝试获取返回7的矩阵的depth()。 I'm not sure what that means. 我不确定那是什么意思。 the Eyes.features matrix is a (or should be) a floating-point matrix Eyes.features矩阵是一个(或应该是)浮点矩阵

to get the Eyes.features i use a gotHogFeatures-Method with 为了得到Eyes.features我使用了一个gotHogFeatures-Method与

    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: descriptorValues表示行向量,并且功能应如下所示:

features: 
{
descriptorValues0
descriptorValues1
...
}

thanks for any help. 谢谢你的帮助。

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 ? Eyes.features是什么类型? It seems that it should be already a Mat1f . 看来它应该已经是Mat1f However, are you sure that features.push_back works as expected? 但是,您确定features.push_back可以正常工作吗? It seems that push_back needs a const Mat& m . 看来push_back需要一个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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM