I am getting an out of memory exception, but am only using about .3GB of RAM. I know Visual Studio allocates 2GB of RAM for 32-bit machines, and I am running in 32-bit mode.
Here is how you can replicate it:
1) Install Emgu CV (can just use NuGet)
2) Use it in Visual Studio (I'm using 2013, not sure if that matters)
3) Add a button that executes this algorithm OnClick:
Note 1: "YourLargeFilename" should be larger than 9,000 by 7,000... too large for me to upload here
Note 2: Use any x, y, and width/height values as your template size (obviously they should be significantly smaller than the size of the source, and should be within the source's bounds)
public void OnClick() {
CroppedBitmap cbmp = getCroppedImage(new Int32Rect(x, y, width, height));
System.Drawing.Bitmap bitmap = BitmapSourceToBitmap((BitmapSource)cbmp));
Image<Gray, byte> source = new Image<Gray, byte>("YourLargeFilename");
Image<Gray, byte> template = new Image<Gray, byte>(bitmap);
Image<Gray, float> result = source.MatchTemplate(template, TemplateMatchingType.CcoeffNormed);
}
public CroppedBitmap getCroppedImage(Int32Rect rectangle) {
sourceBitmapImage = new BitmapImage(new Uri(ofd.FileName));
return new CroppedBitmap((BitmapoSource)sourceBitmapImage, rectangle);
}
private System.Drawing.Bitmap BitmapSourceToBitmap(BitmapSource bitmapSource)
{
System.Drawing.Bitmap bitmap;
using (var outStream = new MemoryStream())
{
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(bitmapSource));
enc.Save(outStream);
bitmap = new System.Drawing.Bitmap(outStream);
}
return bitmap;
}
The error message looks like this:
Exception of type 'System.OutOfMemoryException' was thrown. at Emgu.CV.Image
2.AllocateData(Int32 rows, Int32 cols, Int32 numberOfChannels) at Emgu.CV.Image
2..ctor(Int32 width, Int32 height) at Emgu.CV.Image2.MatchTemplate(Image
2 template, TemplateMatchingType method)
What other information should I provide?