简体   繁体   English

使用 Mat DataType 在 EmguCV 中获取像素值

[英]Get Pixel Values in EmguCV with Mat DataType

I'm Trying to Get Pixel values of Mat Type Images in C# (EmguCV) how can I get Pixel values of Mat images without converting them to Image<> type?!我正在尝试获取 C# 中 Mat 类型图像的像素值 (EmguCV) 如何在不将 Mat 图像转换为 Image<> 类型的情况下获取 Mat 图像的像素值?!

I do it in python efficiently with NumPy arrays... but in C# (Emgu) I Don't Know how I can do that...我在 python 中有效地使用 NumPy arrays...但是在 C# (Emgu) 中我不知道我该怎么做...

Mat image = CvInvoke.Imread(img_path);

this is the image that I read...这是我读到的图像...

There are two ways to access Mat Image's pixel value in EmguCV (C#).在 EmguCV (C#) 中有两种方法可以访问 Mat Image 的像素值。

1- Convert Mat Image to Image<ColorType, DDepth> 1- 将 Mat Image 转换为 Image<ColorType, DDepth>
2- Use Image.Data.GetValue() Functions 2- 使用 Image.Data.GetValue() 函数

1- you can convert your Mat image to Image Format and then access the pixel values just like below: 1- 您可以将 Mat 图像转换为图像格式,然后访问像素值,如下所示:

int row = 0;
int col = 5;
int Channel = 0;
Mat ImageMat = CvInvoke.Imread("Image/Path");
Image<Gray, Byte> ImageFormat = ImageMat.ToImage<Gray, Byte>();
int pixel_value = ImageFormat.Data[row, col, Channel];

2- you can directly access pixel value.GetValue method for Mat Class. but this method returns an object you have to convert to a datatype like an int to float eg. 2-您可以直接访问Mat Class的像素值.GetValue方法。但是此方法返回一个object,您必须将其转换为数据类型,例如将int转换为float,例如。

Mat ImageMat = CvInvoke.Imread("Image/Path");
object pixel_value = ImageMat.Data.GetValue(row, col, Channel);
float pixelVal = Convert.ToInt32(pixel_value);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM