2

我有一个源代码,它在内存流(字节)中给了我一个 jpeg。
我可以将其转换为 System.Drawing.Image,但我不知道如何
将其转换为 Emgu Image。

也许直接转换为 Emgu Image 是可能的?
我在 VS2010 下使用 C# 工作。
谢谢。
西南

4

4 回答 4

2

您可以先将 System.Drawing.Image 对象转换为位图,然后使用该位图创建 Emgu.CV.Image。代码如下:

System.Drawing.Image image;
Bitmap bmpImage = new Bitmap(image);
Emgu.CV.Image = new Emgu.CV.Image<Bgr, Byte>(bmpImage);

更好的是,如果你有内存流,你可以直接从内存流中获取位图

MemoryStream ms;
Bitmap bmpImage = new Bitmap(ms);
Emgu.CV.Image = new Emgu.CV.Image<Bgr, Byte>(bmpImage);
于 2011-06-24T15:50:34.963 回答
1

您可以使用如下代码将数组字节转换为 Emgu Image<,> ...

public Image<Bgr, Byte> CreateImageFromBytesArray(byte[] bytes)
{
     MemoryStream ms = new MemoryStream(bytes);
     Bitmap bmpImage = (Bitmap) Image.FromStream(ms);
     return new Image<Bgr, byte>(bmpImage);         
}
于 2011-03-29T23:31:06.003 回答
0

使用 ps2010 解决方案,我写了这个来从 http 获取图像:

try
{                
    using (WebClient client = new WebClient())
    {                    
        data = client.DownloadData("http://LINK TO PICTURE");
    }       
}
catch (Exception ex)
{
    // error treatment
}

MemoryStream ms = new MemoryStream(data);
Bitmap bmpImage = new Bitmap(Image.FromStream(ms));
Emgu.CV.Image<Bgr, Byte> currentFrame = new Emgu.CV.Image<Bgr, Byte>(bmpImage);
gray = currentFrame.Convert<Gray, Byte>();
于 2012-08-15T05:09:07.510 回答
0

自 Emgu 4.2.0 版以来,没有以位图为参数的图像构造函数。现在有位图的扩展方法:

Bitmap bmpImage = new Bitmap(SomeStream);
var img = bmpImage.ToImage<Bgr, byte>();

历史上的一些细节:http ://www.emgu.com/wiki/index.php/Version_History

于 2021-02-12T16:26:03.337 回答