public void TakePic() { //Console.WriteLine(FrameRate); Mat frame = new Mat(); //frame = capture.QueryFrame(); capture.Grab(); capture.Retrieve(frame, 0); frame.Save("/home/pi/AVA/Photos/" + string.Format("{0:yyyy-MM-dd hh_mm_ss_fftt}", DateTime.Now) + ".jpg"); Debug.DebugStatement("Photo taken", ConsoleColor.White); //Thread.Sleep((int)(1000.0 / FrameRate)); frame.Dispose(); //capture.Dispose(); }
public static void DoMatMagic(string message = null) { if (message != "Magical Mystery Heap fix") { Log.InfoFormat("Magical Mystery Heap fix from '{0}'", message); return; } Log.InfoFormat("Mat test! {0}" , message); var m1 = new Mat(); var m2 = new Mat(); m2.CopyTo(m1); m1.Dispose(); m2.Dispose(); }
public void showFrame() { if (this.InvokeRequired) { try { ShowFrameDelegate SD = new ShowFrameDelegate(showFrame); this.BeginInvoke(SD); } catch { } } else { if (ext == ".jpg") { Emgu.CV.Mat matBefore = CvInvoke.Imread(Text_FilePath.Text); Emgu.CV.Mat matAfter = CvInvoke.Imread(SaveFileName); if (matBefore != null && matAfter != null) { // bitmap是GDI+的物件,所以使用一般釋放記憶體的方式(dispose)對於bitmap是無效的 // 要能夠成功的釋放GDI+物件所佔用的記憶體,必須要使用Windows GDI元件,才能有效的釋放掉bitmap所使用的記憶體 // 將Bitmap物件轉換為平台指標 IntPtr gdibitmapBefore = matBefore.Bitmap.GetHbitmap(); IntPtr gdibitmapAfter = matAfter.Bitmap.GetHbitmap(); // 將bitmap放入至PictureBox的Image屬性 File_Before.Image = Image.FromHbitmap(gdibitmapBefore); File_After.Image = Image.FromHbitmap(gdibitmapAfter); // 進行Bitmap資源的釋放 DeleteObject(gdibitmapBefore); DeleteObject(gdibitmapAfter); } if (matBefore != null) { matBefore.Dispose(); } if (matAfter != null) { matAfter.Dispose(); } GC.Collect(); } else if (FrameCount == 0 || State == (int)PlayState.PlayState_Play) { Emgu.CV.Mat matBefore = objVideoCapture_Before.QueryFrame(); Emgu.CV.Mat matAfter = objVideoCapture_After.QueryFrame(); if (matBefore != null && matAfter != null) { FrameCount = objVideoCapture_Before.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.PosFrames); // bitmap是GDI+的物件,所以使用一般釋放記憶體的方式(dispose)對於bitmap是無效的 // 要能夠成功的釋放GDI+物件所佔用的記憶體,必須要使用Windows GDI元件,才能有效的釋放掉bitmap所使用的記憶體 // 將Bitmap物件轉換為平台指標 IntPtr gdibitmapBefore = matBefore.Bitmap.GetHbitmap(); IntPtr gdibitmapAfter = matAfter.Bitmap.GetHbitmap(); // 將bitmap放入至PictureBox的Image屬性 File_Before.Image = Image.FromHbitmap(gdibitmapBefore); File_After.Image = Image.FromHbitmap(gdibitmapAfter); // 進行Bitmap資源的釋放 DeleteObject(gdibitmapBefore); DeleteObject(gdibitmapAfter); } if (matBefore != null) { matBefore.Dispose(); } if (matAfter != null) { matAfter.Dispose(); } GC.Collect(); } } }