4) 基于指针的直接访问: (简单高效)
- 对于单通道字节型图像:
对于多通道字节型图像:int height = img->height; int width = img->width; int step = img->widthStep; uchar* data = (uchar *)img->imageData; data[i*step+j] = 111;</pre><br><span style="color:rgb(51,153,51)"></span>
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;</pre><br><span style="color:rgb(51,153,51)"></span>
{ 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])); } } } </pre><br><br>