public static void DetectBlobEllipses(string myFile)
        {
            var grayImage = new Image <Gray, byte>(myFile);
            Mat imageCopy = Emgu.CV.CvInvoke.Imread(myFile, Emgu.CV.CvEnum.ImreadModes.Color);
            //grayImage._Not();

            var grayImageCopy = grayImage.Clone();
            var res           = CvInvoke.Threshold(grayImage, grayImageCopy, 170, 255, Emgu.CV.CvEnum.ThresholdType.Binary);

            CvInvoke.Imwrite(Path.GetDirectoryName(myFile) + "\\" + Path.GetFileNameWithoutExtension(myFile) + "-threshold" + Path.GetExtension(myFile), grayImageCopy, new KeyValuePair <Emgu.CV.CvEnum.ImwriteFlags, int>(Emgu.CV.CvEnum.ImwriteFlags.JpegQuality, 95));
            //grayImageCopy._Not();

            // Set our filtering parameters
            // Initialize parameter settiing using cv2.SimpleBlobDetector
            var paramsx = new Emgu.CV.Features2D.SimpleBlobDetectorParams();

            // Set Area filtering parameters
            paramsx.FilterByArea = true;
            paramsx.MinArea      = 1000;

            // Set Circularity filtering parameters
            paramsx.FilterByCircularity = false;
            paramsx.MinCircularity      = 0.9f;

            // Set Convexity filtering parameters
            paramsx.FilterByConvexity = false;
            paramsx.MinConvexity      = 0.2f;

            // Set inertia filtering parameters
            paramsx.FilterByInertia = false;
            paramsx.MinInertiaRatio = 0.01f;

            // Create a detector with the parameters
            var detector = new Emgu.CV.Features2D.SimpleBlobDetector(paramsx);

            // Detect blobs
            var keypoints = detector.Detect(grayImageCopy);
            var keyPoints = new Emgu.CV.Util.VectorOfKeyPoint(keypoints);

            // Draw blobs on our image as red circles
            var blank = imageCopy.Clone();

            Emgu.CV.Features2D.Features2DToolbox.DrawKeypoints(imageCopy, keyPoints, blank, new Bgr(System.Drawing.Color.Red), Emgu.CV.Features2D.Features2DToolbox.KeypointDrawType.DrawRichKeypoints);

            var number_of_blobs = keyPoints.Size;

            CvInvoke.Imwrite(Path.GetDirectoryName(myFile) + "\\" + Path.GetFileNameWithoutExtension(myFile) + "-copy" + Path.GetExtension(myFile), blank, new KeyValuePair <Emgu.CV.CvEnum.ImwriteFlags, int>(Emgu.CV.CvEnum.ImwriteFlags.JpegQuality, 95));
        }
Example #2
0
        private void Circles(object sender, RoutedEventArgs e)
        {
            allPonits = new List <System.Drawing.PointF[]>();
            foreach (var i in imageList)
            {
                Emgu.CV.Features2D.SimpleBlobDetectorParams simpleBlobDetectorParams = new Emgu.CV.Features2D.SimpleBlobDetectorParams();
                simpleBlobDetectorParams.MaxArea             = 300000;
                simpleBlobDetectorParams.FilterByColor       = true;
                simpleBlobDetectorParams.MinThreshold        = 100;
                simpleBlobDetectorParams.MaxThreshold        = 150;
                simpleBlobDetectorParams.ThresholdStep       = 10;
                simpleBlobDetectorParams.MinArea             = 1000;
                simpleBlobDetectorParams.FilterByArea        = true;
                simpleBlobDetectorParams.MinDistBetweenBlobs = 10;
                var blobs  = new Emgu.CV.Features2D.SimpleBlobDetector(simpleBlobDetectorParams).Detect(i);
                var points = Emgu.CV.CvInvoke.FindCirclesGrid(i.Convert <Gray, byte>(), new System.Drawing.Size(4, 11), (Emgu.CV.CvEnum.CalibCgType) 6, new Emgu.CV.Features2D.SimpleBlobDetector(simpleBlobDetectorParams));
                if (points != null)
                {
                    allPonits.Add(points);
                }
            }

            calcPosition();
        }