1.操作像素点
在这里和c++的区别就出来了,c++对像素点的setget用的是at函数。而c#的at函数只能用于get,set用的就是set函数,我一般直接用setget函数.
//
// 摘要:
// Set a value to the specified array element.
//将值设置为指定的数组元素.。
// 参数:
// i0:
// Index along the dimension 0
//沿维度0的索引
// i1:
// Index along the dimension 1
//沿维度1的索引
// value:
//
// 类型参数:
// T:
public void Set<T>(int i0, int i1, T value) where T : struct;
public void Set<T>(int i0, int i1, int i2, T value) where T : struct;
public void Set<T>(int[] idx, T value) where T : struct;
public void Set<T>(int i0, T value) where T : struct;
几种重载,看着有点迷糊。实际上
//来个复杂点的,
for (int i = 0; i < panda.Rows; i++)//遍历所有像素点
{
for (int j = 0; j < panda.Cols; j++)
{
pandax.Set(i, j, (float)j);//x不动,转成float是必须的,参数不一样重载的函数也不一样
// panday.Set(i, j, (float)(panda.Rows - i));//y上下对换
panday.Set(i, j, (float)(i + 5 * Math.Sin(j / 1.0)));//波浪
}
}
对于3通道彩色图像
Vec3b black = new Vec3b(0, 0, 0);//3个char,对应BGR
src.Set(i, j, black);//行,列,vec3b(opencv好奇葩,好多都反着来)
对于单通道灰色图像