您的位置:首页 > 运维架构

opencv中遍历图片数据的两种方法

2012-02-21 19:22 267 查看
方法一:

IplImage *pImg = ...;

int nWidth = pImg->width;

int nHeight = pImg->height;

int nChannels = pImg->nChannels;

int nStep = pImg->widthStep;

for (int i=0; i<nHeight; i++)

for(int j=0; j<nWidth; j++)

for (int k=0; k<nChannels; k++)

{

pImg->imageData[i*nStep + j*nChannels + k] = 255 - pImg->imageData[i*nStep + j*nChannels + k];

}

方法二:

IplImage *image = ...;

int div = 8;

int nl = image->height;

int nc = image->width*image->nChannels;

int step = image->widthStep;

unsigned char *data = (unsigned char *)image->imageData;

for (int i=1; i<nl; i++)

{

for (int j=0; j<nc; j+=image->nChannels)

{

data[j] += div/2;

data[j+1] += div/2;

data[j+2] += div/2;

}

data += step;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: