码迷,mamicode.com
首页 > 其他好文 > 详细

【OpenCV】简单高效地访问图像像素

时间:2015-04-14 13:03:04      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:opencv

对于单通道字节型图像:
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;
//这里注意step不能换成width,数据会4字节对齐,step指每行像素所占字节数
data[i*step+j] = 100;
对于多通道字节型图像:
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] = 100;
对于多通道浮点型图像(假设图像数据采用4字节(32位)行对齐方式):
IplImage* img  = cvCreateImage(cvSize(640,480),IPL_DEPTH_32F,3);
int height     = img->height;
int width      = img->width;
int step       = img->widthStep;
int channels   = img->nChannels;
float * data    = (float *)img->imageData;
data[i*step+j*channels+k] = 100;


【OpenCV】简单高效地访问图像像素

标签:opencv

原文地址:http://blog.csdn.net/lsh_2013/article/details/45039393

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!