opencv 存储的图像类型

OpenCV 图像格式.md

图像深度

图像位深度=比特数+数据类型
C++中OpenCV库的获取方式:(函数原型)

int Mat::depth()

下表是返回值以及对应含义

图像深度 枚举数值 空间大小 范围 等同C++变量
CV_8U 0 8bits 0~255 unsigned char或uint8_t
CV_8S 1 8bits -128~127 char或int8_t
CV_16U 2 16bits 0~65535 ushort,unsigned short int,unsigned short或uint16_t
CV_16S 3 16bits -32768~32767 short,short int或int16_t
CV32S 4 32bits -2147483648~2147483647 int,long或int32_t/int64_t
CV32F 5 32bits 1.18e-38~3.40e38 float或
CV_64F 6 64bits 2.23e-308~1.79e308 double或
CV_USRTYPE1 7 -

图像通道数

C++中OpenCV库的获取方式:(函数原型)

int Mat:channels()

图像类型

图像类型=比特数+数据类型+通道数
存储元素的数据类型:

CV_[位数][带符号与否][类型前缀]C[通道数]

带符号与否:S为符号整型,U为无符号整型,F为浮点型
C++中OpenCV库的获取方式:(函数原型)

int Mat::type()

具体数据类型与返回值关系:

类型 C1 C2 C3 C4
CV_8U 0 8 16 24
CV_8S 1 9 17 25
CV_16U 2 10 18 26
CV_16S 3 11 19 27
CV_32S 4 12 20 28
CV_32F 5 13 21 29
CV_64F 6 14 22 30
用户定义 7

单个元素的访问

种类 C1 C2 C3 C4 C6
uchar8U uchar cv::Vec2b cv::Vec3b cv::Vec4b
char8S
ushort16U
short16S short cv::Vec2s cv::Vec3s cv::Vec4s
int32S int cv::Vec2i cv::Vec3i cv::Vec4i
float32F float cv::Vec2f cv::Vec3f cv::Vec4f cv::Vec6f
double64F double cv::Vec2d cv::Vec3d cv::Vec4d cv::Vec6d

示例如下:

cv::Vec3b vec3b      = img.at<cv::Vec3b>(0,0);
uchar     vec3b0     = img.at<cv::Vec3b>(0,0)[0];
uchar     vec3b1     = img.at<cv::Vec3b>(0,0)[1];
uchar     vec3b2     = img.at<cv::Vec3b>(0,0)[2];
std::cout<<"vec3b = "<<vec3b<<std::endl;
std::cout<<"vec3b0 = "<<(int)vec3b0<<std::endl;
std::cout<<"vec3b1 = "<<(int)vec3b1<<std::endl;
std::cout<<"vec3b2 = "<<(int)vec3b2<<std::endl;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章