opencv 的矩阵数据结构采用了C++ 类的思想。图像处理过程中经常用到访问彩色图像的像素值。 可以采取下列简单的方法:
Mat_<Vec3b> img(240, 320, Vec3b(0, 255, 0));
for(int i=0; i<100, i++)
img(i, i) = Vec3b(255, 255, 255);
for(int i=0; i<img.rows; i++)
for(int j=0; j< img.cols; j++)
img(i, j)[2]^= (uchar)(i^j);