internal static void ShowImage(Mat image, string title = null) { if (title == null) { title = "ImageShowcase"; } ImageShowCase imageShowCase = null; foreach (var showcase in instances) { if (showcase.Text == title) { imageShowCase = showcase; break; } } if (imageShowCase == null) { imageShowCase = new ImageShowCase(); imageShowCase.Text = title; instances.Add(imageShowCase); } imageShowCase.imageBox.Image = image; if (!imageShowCase.Visible) { imageShowCase.Show(); } }
public void GridDetection() { // convert to gray-scaler image Mat image = originalImage.Mat.Clone(); // blur the image CvInvoke.GaussianBlur(image, image, new Size(11, 11), 0); // threshold the image CvInvoke.AdaptiveThreshold(image, image, 255, AdaptiveThresholdType.MeanC, ThresholdType.Binary, 5, 2); CvInvoke.BitwiseNot(image, image); Mat kernel = new Mat(new Size(3, 3), DepthType.Cv8U, 1); Marshal.Copy(new byte[] { 0, 1, 0, 1, 1, 1, 0, 1, 0 }, 0, kernel.DataPointer, 9); CvInvoke.Dilate(image, image, kernel, new Point(-1, -1), 1, BorderType.Default, new MCvScalar(255)); FindOuterGridByFloorFill(image); CvInvoke.Erode(image, image, kernel, new Point(-1, -1), 1, BorderType.Default, new MCvScalar(255)); ImageShowCase.ShowImage(image, "biggest blob"); VectorOfPointF lines = new VectorOfPointF(); CvInvoke.HoughLines(image, lines, 1, Math.PI / 180, 200); // merging lines PointF[] linesArray = lines.ToArray(); //MergeLines(linesArray, image); lines = RemoveUnusedLine(linesArray); Mat harrisResponse = new Mat(image.Size, DepthType.Cv8U, 1); CvInvoke.CornerHarris(image, harrisResponse, 5); DrawLines(lines.ToArray(), image); ImageShowCase.ShowImage(image, "corners"); }