I'm not really sure what the Image<Gray, byte>
class is and how it is implemented, but you're passing a string
to its constructor - are you sure that this is correct? (EDIT: Just found out it is part of the EMGU implementation). I'll show you how you'd normally create an image from the stream:
MemoryStream ms = dict["mypicture.png"]; // This gives you the memory stream from the dictionary
ms.Seek(0, SeekOrigin.Begin); // Go to the beginning of the stream
Bitmap bmp = new Bitmap(ms); // Create image from the stream
Now I suspect you want to create a new "emgu image" from the stream you have using the following constructor:
Image<Bgr, Byte> img1 = new Image<Bgr, Byte>("MyImage.jpg");
Which is - according to the EMGU documentation - supposed to read an image from a file. You don't have a file named "mypicture.png", you have a stream within a dictionary under the key "mypicture.png", which is something totally different. I doubt that the Image<t1, t2>
class is able to read from a stream - at least I didn't see anything like that in the docs.
What you need to call is (using the code I provided above):
Image<Gray, Byte> img1 = new Image<Gray, Byte>(bmp);
All that being said, the code for the Draw
method (which then can't be static, by the way) should read like this:
private Bitmap GetBitmapFromStream(String bitmapKeyName)
{
MemoryStream ms = dict[bitmapKeyName];
ms.Seek(0, SeekOrigin.Begin);
return new Bitmap(ms);
}
public Image<Bgr, Byte> Draw(String modelImageFileName, String observedImageFileName, out long matchTime,int i)
{
Image<Gray, Byte> modelImage = new Image<Gray, byte>(GetBitmapFromStream(modelImageFileName));
Image<Gray, Byte> observedImage = new Image<Gray, byte>(GetBitmapFromStream(observedImageFileName));
}
EDIT
In the comments below you say that you want to reduce the processing time by saving the bitmaps into a memory stream instead of writing to the disk.
I need to ask you the following: Why do you do that in the first place? I notice from the code you posted above that obviously you already have a Bitmap
which you save into the memory stream. Why don't you put the bitmap itself into the dictionary?
Dictionary<string, Bitmap> dict = new Dictionary<string, Bitmap>();
dict.Add("mypicture.png", bmp);
Then you could retrieve it right away with even less time being wasted for storing and reading the image from the stream. The Draw
method then would read:
public Image<Bgr, Byte> Draw(String modelImageFileName, String observedImageFileName, out long matchTime,int i)
{
Image<Gray, Byte> modelImage = new Image<Gray, byte>(dict[modelImageFileName);
Image<Gray, Byte> observedImage = new Image<Gray, byte>(dict[observedImageFileName]);
}