/// <summary> /// Processing loop, captures an image and processes it /// </summary> private void Application_Idle() { while (true) { try { Image <Bgr, byte> tempFrame = captured_frame = CameraManager.GetImage(); if (CaptureSettings.Instance().DEFAULT_DILATATION != 0) { tempFrame._Dilate((int)CaptureSettings.Instance().DEFAULT_DILATATION); } if (CaptureSettings.Instance().DEFAULT_ERODE != 0) { tempFrame._Erode((int)CaptureSettings.Instance().DEFAULT_ERODE); } if (CaptureSettings.Instance().DEFAULT_GAMMA != 1) { tempFrame._GammaCorrect((double)CaptureSettings.Instance().DEFAULT_GAMMA); } if (CaptureSettings.Instance().DEFAULT_INVERT_ENABLED) { tempFrame._Not(); } if (CaptureSettings.Instance().DEFAULT_NORMALIZE_ENABLED) { tempFrame._EqualizeHist(); } // fix rotation if (CalibrationSettings.Instance().CALIBRATION_ROTATION != 0) { tempFrame = tempFrame.Rotate(CalibrationSettings.Instance().CALIBRATION_ROTATION, new Bgr(0, 0, 0), true); } processor.ProcessImage(tempFrame); if (interactiveWindow != null && interactiveWindow.IsVisible) { interactiveWindow.DrawImage(tempFrame, processor); } InputLogic(); } catch { // no-op here } } }
/// <summary> /// Processes current frame /// </summary> private void ProcessFrame() { try { Image <Bgr, byte> tempFrame = null; if (captureFromCam) { captureSetWindow.Frame = CameraManager.GetImage(); } else { captureSetWindow.Frame = captureSetWindow.ImageFrame.Clone(); } // get values of properties from the UI captureSetWindow.Dispatcher.BeginInvoke(new Action(() => { dilatation = captureSetWindow.dilatationSlider.Value; erode = captureSetWindow.erodeSlider.Value; gamma = captureSetWindow.gammaSlider.Value; invert = (bool)captureSetWindow.invertCheck.IsChecked; normalize = (bool)captureSetWindow.normalizeCheck.IsChecked; blackWhite = (bool)captureSetWindow.showBlackWhiteCheck.IsChecked; blur = (bool)captureSetWindow.blurCheck.IsChecked; binary = (bool)captureSetWindow.showBinaryCheck.IsChecked; })); // apply other settings if (dilatation != 0) { captureSetWindow.Frame._Dilate((int)dilatation); } if (erode != 0) { captureSetWindow.Frame._Erode((int)erode); } if (gamma != 1) { captureSetWindow.Frame._GammaCorrect((double)gamma); } if (invert) { captureSetWindow.Frame._Not(); } if (normalize) { captureSetWindow.Frame._EqualizeHist(); } tempFrame = captureSetWindow.Frame.Clone(); if (blackWhite) { tempFrame = tempFrame.Convert <Gray, Byte>().Convert <Bgr, byte>(); } if (blur) { tempFrame = tempFrame.PyrDown().PyrUp(); } captureSetWindow.Processor.ProcessImage(captureSetWindow.Frame); if (binary) { captureSetWindow.captureBox.Image = captureSetWindow.Processor.binarizedFrame; } else { captureSetWindow.captureBox.Image = tempFrame; } } catch (Exception ex) { // no-op here } }