简体   繁体   English

OpenCV-Mat :: convertTo()声明错误。

[英]OpenCV - Mat::convertTo() assertion error.

I just migrated from Ubuntu 10.04 to 11.10 and I am using OpenCV 2.3.1. 我刚刚从Ubuntu 10.04迁移到11.10,并且正在使用OpenCV 2.3.1。 For some reasons now when I do something like: 由于某些原因,当我执行以下操作时:

Mat_<unsigned> a = Mat_<unsigned>(10,2);
Mat_<float> b;

a.convertTo(b,CV_32F); 

I get the following error: 我收到以下错误:

OpenCV Error: Assertion failed (func != 0) in convertTo, file /home/memecs/Desktop/OpenCV-2.3.1/modules/core/src/convert.cpp, line 937
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/memecs/Desktop/OpenCV-2.3.1/modules/core/src/convert.cpp:937: error: (-215) func != 0 in function convertTo

Aborted

and the function asserting is: 函数断言是:

Mat::convertTo(OutputArray _dst, int _type, double alpha, double beta) const
{
    bool noScale = fabs(alpha-1) < DBL_EPSILON && fabs(beta) < DBL_EPSILON;

    if( _type < 0 )
        _type = _dst.fixedType() ? _dst.type() : type();
    else
        _type = CV_MAKETYPE(CV_MAT_DEPTH(_type), channels());

    int sdepth = depth(), ddepth = CV_MAT_DEPTH(_type);
    if( sdepth == ddepth && noScale )
    {
        copyTo(_dst);
        return;
    }

    Mat src = *this;

    BinaryFunc func = noScale ? getConvertFunc(sdepth, ddepth) : getConvertScaleFunc(sdepth, ddepth);
    double scale[] = {alpha, beta};
    int cn = channels();

    ################### THIS IS THROWING THE ASSERTION ERROR ###############
    CV_Assert( func != 0 );


    if( dims <= 2 )
    {
        _dst.create( size(), _type );
        Mat dst = _dst.getMat();
        Size sz = getContinuousSize(src, dst, cn);
        func( src.data, src.step, 0, 0, dst.data, dst.step, sz, scale );
    }
    else
    {
        _dst.create( dims, size, _type );
        Mat dst = _dst.getMat();
        const Mat* arrays[] = {&src, &dst, 0};
        uchar* ptrs[2];
        NAryMatIterator it(arrays, ptrs);
        Size sz((int)(it.size*cn), 1);

        for( size_t i = 0; i < it.nplanes; i++, ++it )
            func(ptrs[0], 0, 0, 0, ptrs[1], 0, sz, scale);
    }
}

Any help? 有什么帮助吗? I really don't know how to solve this problem. 我真的不知道如何解决这个问题。

Mat_<unsigned> is useless with OpenCV. Mat_<unsigned>对OpenCV无效。 None of OpenCV functions supports unsigned int data type. OpenCV函数均不支持unsigned int数据类型。 Try to use signed int or unsigned short instead. 尝试改用有signed intunsigned short They are supported by OpenCV. 它们受OpenCV支持。

Try this please. 请尝试这个。

Mat a = Mat_<unsigned char>(10,2);
Mat b ;
a.convertTo(b,CV_32F);
cout<<"a type"<<endl<<a.depth()<<endl<<endl<<"b type"<<endl<<b.depth()<<endl;

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

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