private void BtnPreviewTemplate_Click(object sender, RoutedEventArgs e) { if (parent.currentScreen != null) { Mat img = parent.selectedScreen;//CvInvoke.Imread("test_save.jpg", Emgu.CV.CvEnum.LoadImageType.Grayscale); Mat warp = new Mat(img.Size, Emgu.CV.CvEnum.DepthType.Cv8U, 1); img.CopyTo(warp); img = ImageProcessor.ApplyBlur(img, 0, 3); img = ImageProcessor.CannyEdgeDetection(img, lowThreshold, highThreshold); img = ImageProcessor.ApplyDilation(img, 3); img = ImageProcessor.ApplyErosion(img, 3); LineSegment2D[] lines = ImageProcessor.HoughLines(img, rho, houghThreshold, minLineLength, maxLineGap); LineSegment2D[] singleLines = Utils.GetSingleLinesFromHoughLines(lines, 20); if (singleLines != null) { Mat mask = ImageProcessor.AddLines(singleLines, Utils.GetRatioOfSelectedArea(Utils.GetPoints(parent.currentScreen.coordinates))); Mat templateImage = ImageProcessor.ApplyMask(warp, mask); parent.template.SetTemplateImageAndMask(templateImage.ToImage <Bgr, byte>(), mask.ToImage <Bgr, byte>()); tempImage.Source = Utils.ToBitmapSource(templateImage); templateMask.Source = Utils.ToBitmapSource(mask); //lblTemplateName.Visibility = Visibility.Visible; //txtTemplateName.Visibility = Visibility.Visible; btnSaveTemplate.Visibility = Visibility.Visible; } else { MessageBox.Show("Couldn't find any lines with the specified parameters"); InitImages(); } } else { MessageBox.Show("You didn't select any screen! ", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } }