opencv学习笔记-入门(7)单通道的图像数据访问

(4) 基于指针的直接访问: (简单高效)

  • 对于单通道字节型图像:
IplImage* img  = cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);
int height     = img->height;
int width      = img->width;
int step       = img->widthStep;
uchar* data    = (uchar *)img->imageData;
data[i*step+j] = 111;

  • 对于多通道字节型图像:
IplImage* img  = cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,3);
int height     = img->height;
int width      = img->width;
int step       = img->widthStep;
int channels   = img->nChannels;
uchar* data    = (uchar *)img->imageData;
data[i*step+j*channels+k] = 111;

另一种访问
for(int y = 0; y < size.height; y++)
	{
		uchar *sptr = src->data.ptr + src->step*y;
		uchar *pDataOutput = dst->data.ptr + src->step*y;
		for(int x = 0; x < size.width; x++, pDataOutput++, sptr+=Nds)
		{
			for(int iD = 0; iD < Nds; iD++)
			{
				data[iD] = sqrt(float(sptr[iD]));
		
			}
		}
	}	


另一种访问:
CvMat *points = cvCreateMat(size, 1, CV_32FC3);
unsigned long int i;
	for(i = 0; i < size; i++)
	{
		points->data.fl[i*3] = (unsigned char)srcarr->imageData[i*3];
		points->data.fl[i*3 + 1] = (unsigned char)srcarr->imageData[i*3 + 1];
		points->data.fl[i*3 + 2] = (unsigned char)srcarr->imageData[i*3 + 2];
 

你可能感兴趣的:(opencv学习笔记-入门(7)单通道的图像数据访问)