public void GrabImages() { while (acquistionThreadActiveEvent.WaitOne(0)) { lock (this.currentFGHandler) { if (this.currentFGHandler != null && this.currentFGHandler.IsInitialized()) { try { HImage imageCaptured = currentFGHandler.GrabImage(); //this.numberOfImagesGrabbedInTriggeredMode++; if (imageCaptured != null) { if (this.ImageGrabbed != null) { ImageGrabbed.Invoke(imageCaptured); } } } catch (HOperatorException hex) { switch (hex.GetErrorCode()) { case 5322: break; //case 5311: // // The fg handle is invalidated. Reset it. // FrameGrabberProperties currentSettings = this.currentFGProperties; // this.currentFGProperties.DeviceID = 0; // this.currentFGProperties.PortIndex = (currentSettings.PortIndex + 1) % 2; // this.CurrentFGProperties = this.currentFGProperties; // this.CurrentFGProperties = currentSettings; // break; default: throw hex; } } catch (Exception ex) { throw new Exception(string.Format("Exception occurred while grabbing images. \r\n Message : {0} \r\n Stack Trace : {1}", ex.Message, ex.StackTrace)); } } else { // Thread.Sleep(1000); } } //Thread.Sleep(100); // Application.DoEvents(); // if (!this.IsDisposed) // { // Action formRefresher = new Action(this.Invalidate); // this.BeginInvoke(formRefresher); // } } this.acquistionThreadTerminateEvent.Set(); }
private void OnImageGrabbed(object sender, EventArgs e) { var mat = new Mat(); if (!videoCapture.Retrieve(mat)) { return; } ImageGrabbed?.Invoke(mat); }
/// <summary> /// Removes the handlers for ImageGrabbed event. /// </summary> public void RemoveImageGrabbedHandlers() { if (ImageGrabbed != null) { foreach (ImageGrabbedHandler handler in ImageGrabbed.GetInvocationList()) { ImageGrabbed -= handler; } } }
/// <summary> /// Grab a frame /// </summary> /// <returns>True on success</returns> public virtual bool Grab() { if (_ptr == IntPtr.Zero) { return(false); } ImageGrabbed?.Invoke(this, new EventArgs()); return(true); }
private void Callback(object state) { var img = images[currImgIdx]; if (currImgIdx == images.Count - 1) { currImgIdx = 0; } else { currImgIdx++; } ImageGrabbed?.Invoke(Utils.GetMat(img.Image)); }
private void OnImageGrabbed(Mat mat) { var sw = new Stopwatch(); sw.Start(); ImageGrabbed?.Invoke(mat); //skip 2/3 of the frames, due to too much work on CPU //if (counter++ % 3 != 0) return; var(faces, eyes) = faceEyeDetector.Detect(mat); if (!faces.Any() || !eyes.Any()) { return; } PersonDetected?.Invoke(mat); FaceDetected?.Invoke(mat, faces, eyes); Console.WriteLine($"Frame processing time : {sw.Elapsed}"); }
private void RaiseImageGrabbedEvent(object sender, ImageGrabbedEventArgs e) => ImageGrabbed?.Invoke(sender, e);
protected void ImageProcess(ImageGrabbedEventArgs e) { ImageGrabbed?.Invoke(this, e); }