public static extern void AddInFrame(ref Frame frame);
public static extern bool PreProcessFrame(Frame frame, ref Frame lastFrame);
private void timer1_Tick(object sender, EventArgs e) { byte[] image = sanyoNetCamera1.GetImage(); MemoryStream memStream = new MemoryStream(image); Bitmap bmp = null; try { bmp = (Bitmap)Image.FromStream(memStream); } catch (System.ArgumentException) { return; } if (this.pictureBox1.Image != null) { //this.pictureBox1.Image.Dispose(); } if (this.live.Checked) { this.pictureBox1.Image = bmp; } //lastImageTime = time; Frame f = new Frame(); f.timeStamp = (int)DateTime.Now.Ticks; f.image = IntPtr.Zero; System.Diagnostics.Debug.WriteLine("before convert"); try { IplImage ipl = BitmapConverter.ToIplImage(bmp); ipl.IsEnabledDispose = false; f.image = ipl.CvPtr; } catch (System.Exception ex) { Debug.WriteLine(ex.Message); this.timer1.Enabled = false; } System.Diagnostics.Debug.WriteLine("after convert"); Frame lastFrame = new Frame(); Debug.WriteLine("input frame: " + f.timeStamp.ToString()); bool groupCaptured = NativeMethods.PreProcessFrame(f, ref lastFrame); Debug.WriteLineIf(lastFrame.image != IntPtr.Zero, "output frame: " + lastFrame.timeStamp.ToString()); if (lastFrame.searchRect.Width == 0 || lastFrame.searchRect.Height == 0) { if (lastFrame.image != IntPtr.Zero) { Debug.WriteLine("==========release memory======="); Cv.Release(ref lastFrame.image); } } else { FrameHistory.Enqueue(lastFrame); } if (groupCaptured) { Frame[] frames = FrameHistory.ToArray(); FrameHistory.Clear(); if (frames.Length <= 0) return; lock (locker) { //System.Diagnostics.Debug.WriteLine(string.Format("enqueue: {0:x}", f.image)); frameQueue.Enqueue(frames); go.Set(); } } }