简体   繁体   English

在OpenCV和C#上获取RGB颜色值

[英]Get RGB color values on OpenCV and C#

I can't find a solution to a simple problem I have: 我找不到一个简单问题的解决方案:

In this code: 在此代码中:

private void ibOriginal_MouseClick(object sender, MouseEventArgs e)
{
    int mouse_get_X = (int)(e.Location.X);
    int mouse_get_Y = (int)(e.Location.Y);

    Byte byte_color = imgOriginal.Data[mouse_get_X, mouse_get_Y, 0];
}

I want to have an RGB value (in a 3-dimensional array of int) of a pixel with X,Y coordinates get by a Mouse Click. 我想通过鼠标单击获得具有X,Y坐标的像素的RGB值(在int的3维数组中)。

Can I make a conversion of "byte_color"? 我可以转换“ byte_color”吗? Is it correct? 这是正确的吗?

I can't find anything in C# that can help me, I'm using EmguCV. 我在C#中找不到任何可以帮助我的东西,我正在使用EmguCV。

First of all, you'll probably want to have: 首先,您可能想要拥有:

imgOriginal.Data[mouse_get_Y, mouse_get_X, 0];  //note X and Y swapped

Secondly, in OpenCV data is stored in bands which you choose with the last index. 其次,在OpenCV中,数据存储在您选择的带上一个索引的区域中。 Their interpretation depends on your image type. 它们的解释取决于您的图像类型。 If you have BGR image type for example, then: 例如,如果您具有BGR图像类型,则:

imgOriginal.Data[mouse_get_Y, mouse_get_X, 0]; // blue
imgOriginal.Data[mouse_get_Y, mouse_get_X, 1]; // green
imgOriginal.Data[mouse_get_Y, mouse_get_X, 2]; // red

Similarly to other image types defined in this namespace: http://www.emgu.com/wiki/files/1.3.0.0/html/b72c032d-59ae-c36f-5e00-12f8d621dfb8.htm 类似于此命名空间中定义的其他图像类型: http : //www.emgu.com/wiki/files/1.3.0.0/html/b72c032d-59ae-c36f-5e00-12f8d621dfb8.htm

When bands have byte resolution they have values from range 0...255, so basically you have an integer already, and you can put it into a text box easily: 当带具有byte分辨率时,它们的值范围为0 ... 255,因此基本上您已经有一个整数,可以轻松地将其放入文本框:

textBox.Text = byteValue.ToString();

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

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