[英]How to convert Bgr pixel to Hsv pixel in EmguCV?
I'd like to convert a Bgr value (one pixel) to an Hsv value. 我想将Bgr值(一个像素)转换为Hsv值。 How can I do that (without writing the conversion code from scratch) in EmguCV? 我怎么能在EmguCV中这样做(不从头开始编写转换代码)?
Please note that I am not interested in converting whole image's color space but only one pixel, therefore CvInvoke.cvCvtColor()
does not work for me. 请注意,我对转换整个图像的颜色空间只有一个像素不感兴趣,因此CvInvoke.cvCvtColor()
对我不起作用。
Okay I already found a way using some help from .NET framework 好吧,我已经找到了一种使用.NET框架帮助的方法
given a Bgr pixel
; 给出一个Bgr pixel
;
1- Converting the color to System.Drawing.Color
: 1-将颜色转换为System.Drawing.Color
:
System.Drawing.Color intermediate = System.Drawing.Color.FromArgb((int)pixel.Red, (int)pixel.Green, (int)pixel.Blue);
2- Constructing Hsv from the intermediate. 2-从中间体构建Hsv。
Hsv hsvPixel = new Hsv(intermediate.GetHue(), intermediate.GetSaturation(), intermediate.GetBrightness());
Cheers. 干杯。
If you want to do this within EmguCV just read the image into a Image the get the value of the pixel and stick it in a Hsv structure. 如果你想在EmguCV中这样做,只需将图像读入图像,获取像素的值并将其粘贴在Hsv结构中。
For example: 例如:
static void Main(string[] args)
{
bool haveOpenCL = CvInvoke.HaveOpenCL;
bool haveOpenClGpu = CvInvoke.HaveOpenCLCompatibleGpuDevice;
CvInvoke.UseOpenCL = true;
Emgu.CV.Image<Bgr, Byte> lenaBgr = new Image<Bgr, Byte>(@"D:\OpenCV\opencv-3.2.0\samples\data\Lena.jpg");
CvInvoke.Imshow("Lena BSG", lenaBgr);
Bgr color = lenaBgr[100, 100];
Console.WriteLine("Bgr: {0}", color.ToString());
Emgu.CV.Image<Hsv, Byte> lenaHsv = new Image<Hsv, Byte>(@"D:\OpenCV\opencv-3.2.0\samples\data\Lena.jpg");
CvInvoke.Imshow("Lena HSV", lenaHsv);
Hsv colorHsv = lenaHsv[100, 100];
Console.WriteLine("HSV: {0}", colorHsv.ToString());
CvInvoke.WaitKey(0);
}
} }
The result: Bgr: [87,74,182] HSV: [176,151,182] 结果:Bgr:[87,74,182] HSV:[176,151,182]
Lena BGR Lena HSV
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.