Skip to content

Instantly share code, notes, and snippets.

@ochilab
Last active August 8, 2023 05:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochilab/d720c9d961ed04b8c707 to your computer and use it in GitHub Desktop.
Save ochilab/d720c9d961ed04b8c707 to your computer and use it in GitHub Desktop.
OpenCVSharpにてMatを利用してピクセルのRGB値を変更する
Mat m = new Mat(@"C:\Users\Public\Pictures\Sample Pictures\tu.jpg");
Cv2.ImShow("before", m);
Mat m2 = new Mat(m.Height, m.Width, MatType.CV_8UC3);
for (int i = 0; i < m2.Height; i++){
for (int j = 0; j < m2.Width; j++){
byte by = 255;
Vec3b pix = m2.At<Vec3b>(i, j);
pix[0]=0; //B
pix[1] = by; //G
pix[2]=0; //R
m2.Set<Vec3b>(i, j, pix);
}
}
Cv2.ImShow("after", m2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment