Emgucv (用c#調用 sharp版 opencv)中的函數,會引起內存泄漏(如下語句),所以改用Aforge實現
Bitmap bmp = new Bitmap("D:\\4.png");
while(true)
{
Image<Gray, Byte> img = new Image<Gray, Byte>(bmp);
}
1.官網下載
http://www.aforgenet.com/framework/downloads.html
下載不下來,可以到此鏈接下下載
http://download.csdn.net/download/robert_cheng/572660
2.如何配置Aforge
建立一份c# 工程,引用下載的Aforge中的dll(在子文件夾中),項目需要,我只引用了Aforge.dll, Aforge.Imaging.dll和Aforge.Math.dll
如下圖所示:
程序開頭引用一下:
using AForge;
using AForge.Imaging;
using AForge.Imaging.Filters;
using AForge.Imaging.Textures;
接下來就可以使用了(具體可以參見down下來的sample例子),這邊我寫個sample,進行簡單的二值化
Bitmap image = new Bitmap(@"D:\new.png");
AForge.Imaging.Image.Clone(image, PixelFormat.Format8bppIndexed);
Threshold threshold = new Threshold();
threshold.ThresholdValue = threshold_value;
Bitmap binaryimage = threshold.Apply(image);
binaryimage.Save("D:\\gray.png");