opencv学习笔记4:用.at访问图像像素时报错

问题描述:

opencv用.at访问图像像素时报错

OpenCV Error: Assertion failed (((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in cv::Mat::at, file d:\opencv\opencv3.1.0\opencv\build\include\opencv2\core\mat.inl.hpp, line 919

原因分析:

image.at<数据类型>(row,col)中的“数据类型”写错了,一定要清楚自己要访问的图像的数据类型


解决方案:

以下是Mat类型与数据类型对应关系:

Unsigned 8bits uchar 0~255
Mat: CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4

Signed 8bits char -128~127
Mat: CV_8SC1,CV_8SC2,CV_8SC3,CV_8SC4

Unsigned 16bits ushort 0~65535
Mat: CV_16UC1,CV_16UC2,CV_16UC3,CV_16UC4

Signed 16bits short -32768~32767
Mat: CV_16SC1,CV_16SC2,CV_16SC3,CV_16SC4

Signed 32bits int -2147483648~2147483647
Mat: CV_32SC1,CV_32SC2,CV_32SC3,CV_32SC4

Float 32bits float -1.1810-38~3.4010-38
Mat: CV_32FC1,CV_32FC2,CV_32FC3,CV_32FC4

Double 64bits double
Mat: CV_64FC1,CV_64FC2,CV_64FC3,CV_64FC4

下面是如何查看图像的Mat类型:
cout< opencv学习笔记4:用.at访问图像像素时报错_第1张图片

你可能感兴趣的:(opencv,c++)