示例#1
0
 // use circle detection only
 private static void CircleOnly(CvCapture cap, CvWindow winScr)
 {
     srcImage       = PerspectiveCorretoin.GetCorrectedImage(cap.QueryFrame());
     gray           = new IplImage(srcImage.Size, BitDepth.U8, 1);
     blurKernelSize = new Size(9, 9);
     while (CvWindow.WaitKey(10) != 27)
     {
         srcImage = PerspectiveCorretoin.GetCorrectedImage(cap.QueryFrame());
         ShowFPS();
         FindCircle(srcImage, winScr);
     }
 }
示例#2
0
        // find circles/dots using blob detection
        private static void FindBlob(CvCapture cap, CvWindow winScr)
        {
            SimpleBlobDetector.Params blobParameters = new SimpleBlobDetector.Params();

            // threshold (gray value)
            blobParameters.MinThreshold = blobMinThreshold;
            blobParameters.MaxThreshold = blobMaxThreshold;
            // area (pixel count)
            blobParameters.FilterByArea = true;
            blobParameters.MinArea      = blobMinArea;
            blobParameters.MaxArea      = blobMaxArea;
            // circularity
            blobParameters.FilterByCircularity = true;
            blobParameters.MinCircularity      = blobMinCircularity;
            // convexity - probably not needed - maybe eleminates false positives
            blobParameters.FilterByConvexity = true;
            blobParameters.MinConvexity      = blobMinConvexity;
            //// inertia - what does the values mean exactly
            //blobParameters.FilterByInertia = true;
            //blobParameters.MinInertiaRatio =

            SimpleBlobDetector blobDetector = new SimpleBlobDetector(blobParameters);

            gray = new IplImage(cap.QueryFrame().Size, BitDepth.U8, 1);

            while (CvWindow.WaitKey(10) != 27)
            {
                IplImage iplImage = PerspectiveCorretoin.GetCorrectedImage(cap.QueryFrame());
                Cv.CvtColor(iplImage, gray, ColorConversion.RgbToGray);

                Mat mat = new Mat(gray);
                mat.PyrDown(new Size(mat.Width / 2, mat.Height / 2));

                KeyPoint[] keypoints = blobDetector.Detect(mat);

                foreach (KeyPoint item in keypoints)
                {
                    Cv.DrawCircle(gray, new CvPoint2D32f(item.Pt.X, item.Pt.Y), (int)(item.Size * 3), CvColor.Green);
                    Console.WriteLine("Found blob | size = " + item.Size);
                }
                winScr.Image = gray;
            }
        }