private void DisplayCam() { while (videoCapture.IsOpened) { var frame = videoCapture.QueryFrame(); FrameGrabbed?.Invoke(this, new FrameGrabbedEventArgs { Frame = frame.Bitmap }); var barcodeReader = new BarcodeReader(); var barcodeDetected = barcodeReader.Decode(frame.Bitmap); if (barcodeDetected != null) { BarcodeDetected?.Invoke(this, new BarcodeDetectedEventArgs { DecodedText = barcodeDetected.Text }); return; } } }
private void DisplayCam() { while (videoCapture.IsOpened) { Mat frame; try { frame = videoCapture.QueryFrame(); } catch { LibraryDataIO.Instance.UILogger.LogError("Camera stopped."); return; } var gray = new Mat(); //Prepares a gray frame and increases its brightness & contrast CvInvoke.CvtColor(frame, gray, ColorConversion.Bgr2Gray); CvInvoke.EqualizeHist(gray, gray); var square = FrameSquarePicture(frame.Bitmap, camSize.Width, camSize.Height); FrameGrabbed?.Invoke(this, new FrameGrabbedEventArgs { Frame = square }); frame.Dispose(); Rectangle[] facesDetected = faceRecognition.DetectFaces(gray); //Forget the previously detected face so if no faces were detected in current iteration, //the same value wouldn't get stored detectedFace = null; foreach (Rectangle face in facesDetected) { var grayFace = new Mat(gray, face); detectedFace = grayFace.ToImage <Gray, byte>(); gray.Dispose(); CvInvoke.Resize(detectedFace, detectedFace, new Size(100, 100), 0, 0, Inter.Cubic); if (isTrained) { var label = faceRecognition.Recognize(detectedFace); if (label != "") { tokenSource.Cancel(); ExistingUserRecognised?.Invoke(this, new FaceRecognisedEventArgs { Label = label }); return; } } if (saved) { NewUserRegistered?.Invoke(this, new FaceRecognisedEventArgs { Label = userLabel }); return; } break; } } }