【发布时间】:2011-11-30 18:22:13
【问题描述】:
我刚刚从 Ubuntu 10.04 迁移到 11.10,我正在使用 OpenCV 2.3.1。 由于某些原因,现在当我执行以下操作时:
Mat_<unsigned> a = Mat_<unsigned>(10,2);
Mat_<float> b;
a.convertTo(b,CV_32F);
我收到以下错误:
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
而函数断言是:
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);
}
}
有什么帮助吗?我真的不知道如何解决这个问题。
【问题讨论】:
-
OpenCV 为您在参考中看到的每个函数在版本表上保存了表格,每个函数都适用于每种可能的单元格类型(您看到的断言只是检查 OpenCV 是否能够找到适合的函数所需的类型 - 显然他不能)。大多数函数可以处理所有定义的 OpenCV 类型,有些则不能(例如 - 重新映射无法处理双精度 - CV_64F)。 non 可以处理“无符号”类型,坚持使用 char、short、int、float、double 和 OpenCV 向量类型
-
解决了这个问题。谢谢!