0

I just migrated from Ubuntu 10.04 to 11.10 and I am using 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.

2
  • OpenCV holds withing tables upon tables of versions for every function you can see in the reference, each for every cell type possible (the assert you've seen just checks if OpenCV was able to find a function fitting the desired types - clearly he couldn't). most functions can handle all defined OpenCV types, some can't (example - remap cant handle doubles - CV_64F). non can handle the type "unsigned", stick with char, short, int, float, double and the OpenCV vector types Commented Nov 30, 2011 at 18:49
  • That solved the problem. Thanks! Commented Nov 30, 2011 at 19:05

2 Answers 2

3

Mat_<unsigned> is useless with OpenCV. None of OpenCV functions supports unsigned int data type. Try to use signed int or unsigned short instead. They are supported by OpenCV.

Sign up to request clarification or add additional context in comments.

Comments

1

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; 

1 Comment

You may want to explain your answer for the benefit of the OP

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.