opencv Mat基础

Mat
Mat由两部分构成

matrix header
pointer to the matrix containing the pixel values

Mat is basically a class with two data parts: the matrix header (containing information such as the size of the matrix, the method used for storing, at which address is the matrix stored, and so on) and a pointer to the matrix containing the pixel values (taking any dimensionality depending on the method chosen for storing) . The matrix header size is constant, however the size of the matrix itself may vary from image to image and usually is larger by orders of magnitude.

Mat A, C;                          // creates just the header parts
A = imread(argv[1], IMREAD_COLOR); // here we'll know the method used (allocate matrix)
Mat B(A);                                 // Use the copy constructor
C = A;                                    // Assignment operator

A,B,C的matrix header不同,但是pointer是一样的.指向同样的内存.修改一个会影响另一个.

Mat D (A, Rect(10, 10, 100, 100) ); // using a rectangle
Mat E = A(Range::all(), Range(1,3)); // using row and column boundaries

可以通过如上代码方式使得matrix header指向全部数据的一个子集.

Mat F = A.clone();
Mat G;
A.copyTo(G);

opencv提供了深拷贝的方法 cv::Mat::clone() and cv::Mat::copyTo() ,会将数据部分也拷贝.

存储方式
opencv默认的是bgr的顺序.
颜色空间有好多种

RGB is the most common as our eyes use something similar, however keep in mind that OpenCV standard display system composes colors using the BGR color space (a switch of the red and blue channel).
The HSV and HLS decompose colors into their hue, saturation and value/luminance components, which is a more natural way for us to describe colors. You might, for example, dismiss the last component, making your algorithm less sensible to the light conditions of the input image.
YCrCb is used by the popular JPEG image format.
CIE Lab* is a perceptually uniform color space, which comes handy if you need to measure the distance of a given color to another color.

Mat M(2,2, CV_8UC3, Scalar(0,0,255));
CV_[The number of bits per item][Signed or Unsigned][Type Prefix]C[The channel number]
比如CV_8UC3代表每个像素值是一个8bit的unsigned char代表(表达范围0-255),有3个通道.

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值