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;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章