private void ProcessAndDisplayImg() { UpdateParameters(); var currentImage = cc.ProcessImg(filePath); imgWindow.Source = CvUtils.ToBitmapSource(currentImage.Mat); }
private void bStart_Click(object sender, RoutedEventArgs e) { IImage img; if (String.IsNullOrEmpty(filePath)) { return; } UpdateParameters(); img = cc.ProcessImg(filePath); imgWindow.Source = CvUtils.ToBitmapSource(img); }
private void bProcessFolder_Click(object sender, RoutedEventArgs e) { if (!String.IsNullOrEmpty(filePath)) { string[] fileList; fileList = Directory.GetFiles(folderPath); string newFolder = folderPath + "Processed\\"; System.IO.Directory.CreateDirectory(newFolder); foreach (string s in fileList) { getFileNameNoExt(s); CvUtils.SaveImage(cc.ProcessImg(s), newFolder + getFileNameNoExt(s) + ".tif", s); counter++; } System.Windows.MessageBox.Show("Complete! " + counter + " files processed."); } }
private void bSave_Click(object sender, RoutedEventArgs e) { CvUtils.SaveImage(cc.ProcessImg(filePath), filePath + "_Copy.tif", filePath); counter++; }
public Image <Bgra, byte> ProcessImg(Image <Bgra, byte> img) { Image <Bgra, byte> maskBgra; VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint(); Image <Gray, byte> mask, maskTemp; VectorOfPoint largestContour; System.Drawing.Rectangle croppingRectangle; mask = new Image <Gray, byte>(img.Width, img.Height, new Gray(255)); maskBgra = new Image <Bgra, byte>(img.Width, img.Height, new Bgra(0, 0, 0, 0)); CvInvoke.CvtColor(img, mask, ColorConversion.Bgra2Gray); if (useGaussianFilter) { CvInvoke.GaussianBlur(mask, mask, new System.Drawing.Size(gaussianFilterSize, gaussianFilterSize), 0); } if (!inverseThreshold) { CvInvoke.Threshold(mask, mask, CvUtils.DetermineThreshold(mask), Byte.MaxValue, ThresholdType.Binary); } else { CvInvoke.Threshold(mask, mask, threshLevel, Byte.MaxValue, ThresholdType.BinaryInv); } if (useMorphOpen) { CvInvoke.MorphologyEx(mask, mask, MorphOp.Open, morphOpenKernel, new System.Drawing.Point(-1, -1), 1, BorderType.Default, new MCvScalar()); } if (useMorphClose) { CvInvoke.MorphologyEx(mask, mask, MorphOp.Close, morphCloseKernel, new System.Drawing.Point(-1, -1), 1, BorderType.Default, new MCvScalar()); } if (useErode) { CvInvoke.MorphologyEx(mask, mask, MorphOp.Erode, erodeKernel, new System.Drawing.Point(-1, -1), 1, BorderType.Default, new MCvScalar()); } maskTemp = mask.Clone(); CvInvoke.FindContours(maskTemp, contours, null, RetrType.List, ChainApproxMethod.ChainApproxNone); largestContour = CvUtils.BiggestContour(contours); croppingRectangle = CvInvoke.BoundingRectangle(largestContour); if (useFindContours) { if (useContourApprox) { double epsillon = contourApproxConstant * CvInvoke.ArcLength(largestContour, true); CvInvoke.ApproxPolyDP(largestContour, largestContour, epsillon, true); } maskBgra.Draw(largestContour.ToArray(), new Bgra(255, 255, 255, 255), -1); } else { CvInvoke.CvtColor(mask, maskBgra, ColorConversion.Gray2Bgra); // might not create transparent background } CvInvoke.BitwiseAnd(img, maskBgra, img); img.ROI = croppingRectangle; return(img); }