前言
陣列的數(shù)據(jù)類型定義了為陣列的每個元素(圖片中的像素)分配的比特數(shù)以及如何使用這些比特數(shù)表示元素的值是牢。
單通道陣列
Returns the depth of a matrix element.
The method returns the identifier of the matrix element depth (the type of each individual channel). For example, for a 16-bit signed element array, the method returns CV_16S . A complete list of matrix types contains the following values:
CV_8U (8 bit 無符號整數(shù))8-bit unsigned integers ( 0..255 )
CV_8S (8 bit 有符號整數(shù))8-bit signed integers ( -128..127 )
CV_16U(16 bit 無符號整數(shù))16-bit unsigned integers ( 0..65535 )
CV_16S (16 bit 有符號整數(shù))16-bit signed integers ( -32768..32767 )
CV_32S (32 bit 有符號整數(shù))32-bit signed integers ( -2147483648..2147483647 )
CV_32F (32 bit 浮點數(shù))32-bit floating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN )
CV_64F (64 bit 浮點數(shù))64-bit floating-point numbers ( -DBL_MAX..DBL_MAX, INF, NAN )
圖像數(shù)據(jù)在計算機內(nèi)存中的存儲順序為以圖像最左上點(也可能是最左下點)開始朗涩。
舉例來說:下圖展示了一個使用8 bit無符號整數(shù)的單通道陣列澄耍。因為數(shù)據(jù)類型是8 bit無符號整數(shù)膛堤,因此這個陣列的每個元素為0-255的值侍咱。
多通道陣列
CV_8UC1 (單通道陣列芽偏,8 bit 無符號整數(shù))
CV_8UC2 (2通道陣列腰池,8 bit 無符號整數(shù))
CV_8UC3 (3通道陣列隙疚,8 bit 無符號整數(shù))
CV_8UC4 (4通道陣列壤追,8 bit 無符號整數(shù))
CV_8UC(n) (n通道陣列,8 bit 無符號整數(shù) (n 可以從 1 到 512) )
舉例來說:下圖展示了一個使用8 bit 無符號整數(shù)的3通道陣列供屉。因為數(shù)據(jù)類型是8 bit無符號整數(shù)行冰,因此這個陣列的每個元素為0-255的值。由于是3通道陣列伶丐,所以陣列由帶有3個元素的元組組成悼做,第一個元組是{122, 102, 32},第二個元組是 {58, 78, 185} 哗魂,以此類推肛走。
IPIIMage位深度
用于指定圖像中的每個像素可以使用的顏色信息數(shù)量。每個像素使用的信息位數(shù)越多录别,可用的顏色就越多朽色,顏色表現(xiàn)就更逼真。
就是說位深度位1的圖像可能有兩個值:黑色和白色组题,位深度位8的圖像由2^8 (256)個可能的值葫男。例如:位深度位8的灰色模式圖像由256種灰色。
RGB圖像有三個顏色通道組成崔列。8位/像素的RGB圖像中每個通道有256個值梢褐。所以RGB有256*256*256個值。
回到正題
構(gòu)造方法(行數(shù)(高度),列數(shù)(寬度)利职,陣列)
OpenCV 模版Vec
typedef Vec<uchar, 2>?Vec2b
typedef Vec<uchar, 3> Vec3b
typedef Vec<uchar, 4> Vec4b
typedef Vec<short, 2> Vec2s
typedef Vec<short, 3> Vec3s
typedef Vec<short, 4> Vec4s
typedef Vec<int, 2> Vec2i
typedef Vec<int, 3> Vec3i
typedef Vec<int, 4> Vec4i
typedef Vec<float, 2> Vec2f
typedef Vec<float ,3> Vec3f
typedef Vec<float ,4> Vec4f
typedef Vec<float, 6> Vec6f
typedef Vec<double, 2> Vec2d
typedef Vec<double ,3> Vec3d
typedef Vec<double ,4> Vec4d
typedef Vec<double ,6> Vec6d
例如 單通道CV_8UC1
RGB:
其代碼效果:
持續(xù)更新中...