2011-03-29 83 views
2

我有一个来源,让我在内存流(字节)的JPEG。
我可以将其转换为System.Drawing.Image,但我不知道如何
将其转换为Emgu图像。

也许直接转换为Emgu图像是可能的?
我在C#下工作VS2010。
谢谢。
SW如何从System.Drawing.Image创建Emgu图像?

回答

1

您可以将字节数组转换为图像Emgu <,>用类似下面的代码...

public Image<Bgr, Byte> CreateImageFromBytesArray(byte[] bytes) 
{ 
    MemoryStream ms = new MemoryStream(bytes); 
    Bitmap bmpImage = (Bitmap) Image.FromStream(ms); 
    return new Image<Bgr, byte>(bmpImage);   
} 
+0

您需要将Image.FromStream转换为位图,否则将无法编译。 – Jeff 2013-10-22 18:30:46

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); 
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>();