以下均针对opencv1.0
第一种方法:使用cvGet2D及cvSet2D
对于单通道图像:
IplImage* img = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 1);
for (int i = 0; i < img->height; i++)//height对应图像的行
{
for (int j = 0; j < img->width; j++)//width对应图像的列
{
CvScalar s;
//s = cvGet2D(img, i, j);// get the (i,j) pixel value
s.val[0] = 255;
cvSet2D(img, i, j, s);// set the (i,j) pixel value
}
}
对于多通道图像:
IplImage* img = cvCreateImage(cvSize(640, 480), IPL_DEPTH_32F, 3);
for (int i = 0; i < img->height; i++)//height对应图像的行
{
for (int j = 0; j < img->width; j++)//width对应图像的列
{
CvScalar s;
//s = cvGet2D(img, i, j);// get the (i,j) pixel value
s.val[0] =