/// <summary> /// Invalidates the bitmap causing a redraw /// </summary> public void Invalidate() { //lock (LockObject) //{ BitmapSource.Invalidate(); //} }
void capGrabber_NewFrameArrived(object sender, EventArgs e) { if (Dispatcher != null) { Dispatcher.Invoke(DispatcherPriority.Render, (SendOrPostCallback) delegate { if (BitmapSource != null) { BitmapSource.Invalidate(); UpdateFramerate(); } }, null); } }
/// <summary> /// Invoked when a new frame arrived /// </summary> /// <param name="sender">Sender</param> /// <param name="e">EventArgs</param> private void capGrabber_NewFrameArrived(object sender, EventArgs e) { // Make sure to be thread safe if (Dispatcher != null) { this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Render, (SendOrPostCallback) delegate { if (BitmapSource != null) { BitmapSource.Invalidate(); UpdateFramerate(); } }, null); } }
public override void UpdateFrame(object sender, EventArgs e) { WebCam camera = sender as WebCam; populateBitMap(camera.ImageBuffer, (int)(ImagerWidth * ImagerHeight * 3)); Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render, (SendOrPostCallback) delegate { if (ImagerWidth != default(double) && ImagerHeight != default(double)) { BitmapSource.Invalidate(); GC.Collect(); //this is due to a bug in InteropBitmap which causes memory leaks for 24 bit bitmaps... MS: FIX IT! } }, null); }
/// <summary> /// The <see cref="ISampleGrabberCB.BufferCB{Double,IntPtr, Int32}"/> buffer callback method. /// Gets called whenever a new frame arrives down the stream in the SampleGrabber. /// Updates the memory mapping of the OpenCV image and raises the /// <see cref="FrameCaptureComplete"/> event. /// </summary> /// <param name="sampleTime">Starting time of the sample, in seconds.</param> /// <param name="buffer">Pointer to a buffer that contains the sample data.</param> /// <param name="bufferLength">Length of the buffer pointed to by pBuffer, in bytes.</param> /// <returns>Returns S_OK if successful, or an HRESULT error code otherwise.</returns> int ISampleGrabberCB.BufferCB(double sampleTime, IntPtr buffer, int bufferLength) { ////long last = this.stopwatch.ElapsedMilliseconds; ////Console.Write("BufferCB called at: "); ////Console.Write(last); ////Console.WriteLine(" ms"); if (buffer != IntPtr.Zero) { // Do not skip frames here by default. // We skip the processing in the Tracker class if it is not fast enough if (!this.skipFrameMode) { // Check mapping if it is not already released and the buffer is running if (this.map != IntPtr.Zero) { // This is fast and lasts less than 1 millisecond. CopyMemory(this.map, buffer, bufferLength); Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render, (SendOrPostCallback) delegate { BitmapSource.Invalidate(); }, null); try { // Send new image to processing thread if (this.FrameCaptureComplete != null) { this.FrameCaptureComplete(this.videoImage); } } catch (ThreadInterruptedException e) { ErrorLogger.ProcessException(e, false); } catch (Exception we) { ErrorLogger.ProcessException(we, false); } } } } return(0); }
public override void UpdateFrame(object sender, EventArgs e) { WebCam camera = sender as WebCam; SelectedCameraIndex = camera.WebCamID; if (camera.ImageBuffer == null) { return; } if (ImagerWidth != default(double) && ImagerHeight != default(double) && SelectedCameraIndex > -1 && SelectedCameraIndex < WebcamManager.NumberConnectedCameras()) { try { if (motionBuffer == null || motionBuffer.Length != camera.ImageBuffer.Length) { motionBuffer = new byte[(int)(camera.ImageBuffer.Length)]; } int scaledRoiX = Math.Max(Math.Min(Convert.ToInt32(ImagerWidth * RoiX), Convert.ToInt32(ImagerWidth)), 0); int scaledRoiY = Math.Max(Math.Min(Convert.ToInt32(ImagerHeight * RoiY), Convert.ToInt32(ImagerHeight)), 0); int scaledRoiWidth = Math.Max(Math.Min(Convert.ToInt32(ImagerWidth * RoiWidth), Convert.ToInt32(ImagerWidth)), 0); int scaledRoiHeight = Math.Max(Math.Min(Convert.ToInt32(ImagerWidth * RoiHeight), Convert.ToInt32(ImagerHeight)), 0); if (Detector.UpdateBackground(camera.ImageBuffer, motionBuffer, Convert.ToInt32(ImagerWidth), Convert.ToInt32(ImagerHeight), MotionAreaPercentageSensitivity, MotionDiffSensitivity, TimeSensitivity, scaledRoiX, scaledRoiY, scaledRoiWidth, scaledRoiHeight)) { if (Detector.IsMotionDetected()) { OnMotionDetected(EventArgs.Empty); // trigger event } if (showBackground) { Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render, (SendOrPostCallback) delegate { populateBitMap(Detector.resizedOutImage.Bytes, (int)(ImagerWidth * ImagerHeight * 3)); BitmapSource.Invalidate(); GC.Collect(); //this is due to a bug in InteropBitmap which causes memory leaks for 24 bit bitmaps... MS: FIX IT! }, null); } } } catch (Emgu.CV.Util.CvException ex) { System.Windows.Forms.MessageBox.Show(ex.ErrorMessage); } } }
public void Invalidate() { BitmapSource.Invalidate(); }