Mat mat = new Mat("lenna.png", LoadMode.Color);
for (int y = 0; y < mat.Height; y++)
{
for (int x = 0; x < mat.Width; x++)
{
Vec3b color = mat.Get<Vec3b>(y, x);
byte temp = color.Item0;
color.Item0 = color.Item2; // B <- R
color.Item2 = temp; // R <- B
mat.Set<Vec3b>(y, x, color);
}
}
Mat mat = new Mat("lenna.png", LoadMode.Color);
var indexer = mat.GetGenericIndexer<Vec3b>();
for (int y = 0; y < mat.Height; y++)
{
for (int x = 0; x < mat.Width; x++)
{
Vec3b color = indexer[y, x];
byte temp = color.Item0;
color.Item0 = color.Item2; // B <- R
color.Item2 = temp; // R <- B
indexer[y, x] = color;
}
}
Mat mat = new Mat("lenna.png", LoadMode.Color);
var mat3 = new Mat<Vec3b>(mat); // cv::Mat_
var indexer = mat3.GetIndexer();
for (int y = 0; y < mat.Height; y++)
{
for (int x = 0; x < mat.Width; x++)
{
Vec3b color = indexer[y, x];
byte temp = color.Item0;
color.Item0 = color.Item2; // B <- R
color.Item2 = temp; // R <- B
indexer[y, x] = color;
}
}
Mat mat = new Mat("foobar.jpg", ImreadModes.Color);
Bitmap bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
Bitmap bitmap = new Bitmap("foobar.jpg");
Mat mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
Mat mat = new Mat("foobar.jpg", ImreadModes.Color);
byte[] bytes1 = mat.ToBytes(".png");
byte[] bytes2;
Cv2.ImEncode(".jpg", mat, out bytes2);
byte[] imageData = System.IO.File.ReadAllBytes("foobar.jpg");
Mat colorMat = Mat.FromImageData(imageData, ImreadModes.Color);
Mat grayscaleMat = Mat.FromImageData(imageData, ImreadModes.GrayScale);
Mat alt = Cv2.ImDecode(imageData, ImreadModes.GrayScale);
觉得好,就一键三连呗(点赞+收藏+关注)