OpenCV MAT小笔记(整理中)

使用Mat类型存储图像,我的一些笔记。

cv::Mat是个模板,里面保存的数据类型是单个元素或者vector。

Mat(rows, cols, type);

rows:高度

cols:宽度

type参数含义如下:

//There are tons of matrix type in CvMat defined in cvtypes.h and listed below.
#define CV_8U   0
#define CV_8S   1
#define CV_16S  2
#define CV_32S  3
#define CV_32F  4
#define CV_64F  5
#define CV_USRTYPE1 6
#define CV_USRTYPE2 7


#define CV_8UC1 (CV_8U + 0*8)
#define CV_8UC2 (CV_8U + 1*8)
#define CV_8UC3 (CV_8U + 2*8)
#define CV_8UC4 (CV_8U + 3*8)


#define CV_8SC1 (CV_8S + 0*8)
#define CV_8SC2 (CV_8S + 1*8)
#define CV_8SC3 (CV_8S + 2*8)
#define CV_8SC4 (CV_8S + 3*8)


#define CV_16SC1 (CV_16S + 0*8)
#define CV_16SC2 (CV_16S + 1*8)
#define CV_16SC3 (CV_16S + 2*8)
#define CV_16SC4 (CV_16S + 3*8)


#define CV_32SC1 (CV_32S + 0*8)
#define CV_32SC2 (CV_32S + 1*8)
#define CV_32SC3 (CV_32S + 2*8)
#define CV_32SC4 (CV_32S + 3*8)


#define CV_32FC1 (CV_32F + 0*8)
#define CV_32FC2 (CV_32F + 1*8)
#define CV_32FC3 (CV_32F + 2*8)
#define CV_32FC4 (CV_32F + 3*8)


#define CV_64FC1 (CV_64F + 0*8)
#define CV_64FC2 (CV_64F + 1*8)
#define CV_64FC3 (CV_64F + 2*8)
#define CV_64FC4 (CV_64F + 3*8)

访问元素:

方式1

比如是CV_8UC1类型的,

image.at<unsigned char>(1,1);//得到像素点的值。

方式2

(这部分稍后重新整理一下)

Mat& ScanImageAndReduceC(Mat& I, const uchar* const table)    
{    
// 只接受char类型矩阵    
    
CV_Assert(I.depth() != sizeof(uchar));    
    
int channels = I.channels();      
int nRows = I.rows*channels;      
int nCols = I.cols;    
    
if (I.isContinuous())    
  {    
  nCols*= nRows;    
  nRows = 1;    
  }    
    
int i,j;    
uchar* p;      
for( i = 0; i < nRows; ++i)    
  {    
  p = I.ptr<uchar>(i);    
for ( j = 0; j < nCols; ++j)    
{   
p[j] = table[p[j]];    
}    
return I;    
   
}    


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值