简体   繁体   English

如何将图像类型转换为图像<Bgr, Byte> ?

[英]How to convert Image type to Image<Bgr, Byte>?

Any Idea how to convert Image type to Image<Bgr, Byte> type?知道如何将Image类型转换为Image<Bgr, Byte>类型吗?

I get the image from PictureBox Control and I need to convert it to Image<Bgr, Byte> type.我从PictureBox Control 获取图像,我需要将其转换为Image<Bgr, Byte>类型。

Image pictureBoxImage = pictureBox.Image;
Image<Bgr, Byte> image = // ...

According the documentation : 根据文档

Creating image from Bitmap 从位图创建图像

It is also possible to create an Image<TColor, TDepth> from a .Net Bitmap object 也可以从.Net Bitmap对象创建Image<TColor, TDepth>

So, you should be able to do: 因此,您应该能够:

var image = new Image<Bgr, Byte>(new Bitmap(pictureBox.Image));

You can also do it like this: 您也可以这样:

Image<Bgr, Byte> IMG = new Image<Bgr, byte>((Bitmap)pictureBox1.Image);

OR 要么

var IMG = new Image<Bgr, byte>((Bitmap)pictureBox1.Image);

For Emgu.CV 4.5 I had to add the Emgu.CV.Bitmap package and use bitmap.ToImage<Bgr, byte>() :对于 Emgu.CV 4.5,我必须添加 Emgu.CV.Bitmap 包并使用bitmap.ToImage<Bgr, byte>()

using (Bitmap bitmap = new Bitmap(pictureBox.Image))
{
    Image<Bgr, byte> image = bitmap.ToImage<Bgr, byte>();
}

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

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