这段代码在Debug模式下会抛出一个异常。而在Release模式下,会得到预期的输出值0。
#include <opencv2\opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(){
Mat image;
image = Mat::zeros(5,5,CV_8UC1);
try{
cout<< image.at<unsigned int>(1,1)<<"\n";
}
catch(Exception ex){
cout<< ex.msg;
}
cin.get();
return 0;
}
抛出异常的文本为:
OpenCV错误:断言失败(dims <= 2 && data && (unsigned)i0 < (unsigned)size.p [0] && (unsigned)(i1 * DataType<_Tp> :: channels) < (unsigned)(size.p [1] * channels()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3 ) - 1))*4) & 15) == elemSize1()),位置未知,文件 c:\users\tim\document s\code\opencv\build\include\opencv2\core\mat.hpp,第537行
OpenCV版本为2.4.6,并且可执行文件动态链接到调试库。
template<typename _Tp> inline _Tp& Mat::at(int i0, int i1) { CV_DbgAssert( dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] && (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channels()) && CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1()); return ((_Tp*)(data + step.p[0]*i0))[i1]; }
- Tim