CvMat、Mat、IplImage、cvarr类型转换 初始化,像素操作

IplImage

定义

IplImage结构来源于Intel的另外一个函数库Intel Image Processing Library (IPL),该函数库主要是针对图像处理。

初始化

IplImage * cvLoadImage(const char * filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR)); //load images from specified image 
IplImage * cvCreateImage(CvSize size, int depth, int channels);  //allocate memory


IplImage* image=cvLoadImage("D:\\123.jpg",-1);
IplImage* fA ;
fA = cvCreateImage(cvSize(img->width, img->height), IPL_DEPTH_32F, img->nChannels);//cvsize(列,行),跟mat不同

释放空间

	cvReleaseImage( &A );

访问元素

单通道

uchar val = ((uchar *)(img->imageData + i*img->widthStep))[j];

三通道

IplImage* img = cvLoadImage("test.bmp", 1);  
for (int i = 0; i < img->height; i++)  
{  
  for (int j = 0; j < img->width; j++)  
  {  
    int bVal = ((uchar *)(img->imageData + i*img->widthStep))[j*img->nChannels + 0]; // B  
    int gVal = ((uchar *)(img->imageData + i*img->widthStep))[j*img->nChannels + 1]; // G  
    int rVal = ((uchar *)(img->imageData + i*img->widthStep))[j*img->nChannels + 2]; // R  
    cout<<"B="<

cvMat

cvMat ->IplImage


CvMat M;
IplImage* img = cvCreateImage(M.size(), M.depth(), M.channels());
cvConvert(&M, img);  

mat

mat指针固定为uchar 类型。必须强制转换。

Mat src(1000,1000,CV_32F);
float* myptr = (float*)src.data;

mat->IplImage

	Mat A = Mat(3, 2, CV_32FC1, a);
    IplImage *A_;
	A_ = cvCreateImage(cvSize(2,3), IPL_DEPTH_32F, 1);
	*A_ = (IplImage)(A);

读取像素

for(i)//row
	uchar* data=img.ptr(i);//弟i行首地址,mat数据是uchar类型。
	for j//col
		data[j]
	end
end

cvArr *

就是void *

ref
三者定义结构
https://www.cnblogs.com/summerRQ/articles/2406109.html

相互转换
https://blog.csdn.net/bagboy_taobao_com/article/details/47048249

你可能感兴趣的:(图像处理基础)