예제 #1
0
파일: GlintBlob.cs 프로젝트: DeSciL/Ogama
        public GlintConfiguration(int numGlints)
        {
            count = numGlints;
            centers = new GTPoint[numGlints];
            blobs = new Blobs();

            for (int i = 0; i < numGlints; i++)
            {
                centers[i] = new GTPoint();
                blobs.BlobDir[i] = new Blob();
            }
        }
예제 #2
0
파일: GlintBlob.cs 프로젝트: DeSciL/Ogama
        public GlintConfiguration(GlintConfiguration src)
        {
            count = src.Count;
            centers = new GTPoint[count];
            blobs = new Blobs();

            for (int i = 0; i < count; i++)
            {
                centers[i] = new GTPoint(src.centers[i]);
                blobs.BlobDir[i] = new Blob();
                blobs.BlobDir[i] = src.blobs.BlobDir.ElementAt(i).Value;
            }
        }
예제 #3
0
파일: GlintBlob.cs 프로젝트: DeSciL/Ogama
        public GlintConfiguration(Blobs blobs)
        {
            count = blobs.Count;
            centers = new GTPoint[blobs.Count];
            int i = 0;

            foreach (Blob b in blobs.BlobList)
            {
                centers[i] = new GTPoint(b.CenterOfGravity.X, b.CenterOfGravity.Y);
                i++;
            }

            //OrderGlints();

            this.blobs = blobs;
        }
예제 #4
0
    public Blobs DetectBlobs(Image<Gray, byte> image, int threshold, double minSize, double maxSize, bool isGlint)
    {
      // Detect blobs
      if (isGlint) // Todo: Run recursive blob detection on small ROI images for improved detection/performance
        blobCounter.ProcessImage(image.ThresholdBinary(new Gray(threshold), new Gray(255)));
      else
        blobCounter.ProcessImage(image.ThresholdToZeroInv(new Gray(threshold)));

      // Filtering 
      if (isFiltering) // turn off above
      {
        blobCounter.FilterBlobs = true;
        blobCounter.MinHeight = (int)minSize;
        blobCounter.MinWidth = (int)minSize;
        blobCounter.MaxHeight = (int)maxSize;
        blobCounter.MaxWidth = (int)maxSize;
        blobCounter.ObjectsOrder = ObjectsOrder.Area;
      }

      // Get blob info
      var blobs = new Blobs(blobCounter.GetObjectsInformation());

      //grahamScan = new GrahamConvexHull();

      // Set blobs properties (edges etc)
      foreach (Blob blob in blobs.BlobDir.Values)
      {
        var leftEdge = new List<IntPoint>();
        var rightEdge = new List<IntPoint>();
        var topEdge = new List<IntPoint>();
        var bottomEdge = new List<IntPoint>();

        // collect edge points
        blobCounter.GetBlobsLeftAndRightEdges(blob, out leftEdge, out rightEdge);
        blobCounter.GetBlobsTopAndBottomEdges(blob, out topEdge, out bottomEdge);

        blobs.leftEdges.Add(blob.ID, leftEdge);
        blobs.rightEdges.Add(blob.ID, rightEdge);
        blobs.topEdges.Add(blob.ID, topEdge);
        blobs.bottomEdges.Add(blob.ID, bottomEdge);

        // find convex hull
        //List<IntPoint> edgePoints = new List<IntPoint>();
        //edgePoints.AddRange(leftEdge);
        //edgePoints.AddRange(rightEdge);

        //List<IntPoint> hull = grahamScan.FindHull(edgePoints);
        //blobs.hulls.Add(blob.ID, hull);

        // find quadrilateral
        //List<IntPoint> quadrilateral = PointsCloud.FindQuadrilateralCorners(hull);
        //blobs.quadrilaterals.Add(blob.ID, quadrilateral);

        //// shift all points for vizualization
        //AForge.IntPoint shift = new IntPoint( 1, 1 );

        //PointsCloud.Shift( leftEdge, shift );
        //PointsCloud.Shift( rightEdge, shift );
        //PointsCloud.Shift( topEdge, shift );
        //PointsCloud.Shift( bottomEdge, shift );
        //PointsCloud.Shift( hull, shift );
        //PointsCloud.Shift( quadrilateral, shift );
      }

      return blobs;
    }
예제 #5
0
파일: GlintBlob.cs 프로젝트: DeSciL/Ogama
        public GlintConfiguration(Blob blob0, Blob blob1)
        {
            count = 2;
            centers = new GTPoint[2];
            blobs = new Blobs();

            blobs.BlobDir[0] = blob0;
            blobs.BlobDir[1] = blob1;

            centers[0] = new GTPoint(blob0.CenterOfGravity.X, blob0.CenterOfGravity.Y);
            centers[1] = new GTPoint(blob1.CenterOfGravity.X, blob1.CenterOfGravity.Y);
        }
예제 #6
0
        private static Matrix<int> GetDistanceMatrix(Blobs blobs, int minDistance, int maxDistance)
        {
            int N = blobs.Count;

            var distMatrix = new Matrix<double>(N, N);
            var distMatrixThr = new Matrix<int>(N, N);
            distMatrixThr.SetIdentity();

            for (int i = 0; i < N; i++)
            {
                for (int j = i; j < N; j++)
                {
                    double dist = Operations.Distance(blobs.BlobList[i].CenterOfGravity, blobs.BlobList[j].CenterOfGravity);

                    if (dist >= minDistance && dist <= maxDistance)
                    {
                        distMatrixThr[i, j] = 1;
                    }
                }
            }

            return distMatrixThr;
        }
예제 #7
0
        private GlintConfiguration FilterConfigsByDistance(Blobs blobs, List<Point> combinations,
                                                           GTPoint initialLocation)
        {
            int N = combinations.Count;

            double minDistance = 100000000;
            double avgDist = 0;

            int correctConfigIndex = 0;

            for (int i = 0; i < N; i++)
            {
                double dist1 = Operations.Distance(blobs.BlobList[(int) combinations[i].X].CenterOfGravity, initialLocation);
                double dist2 = Operations.Distance(blobs.BlobList[(int) combinations[i].Y].CenterOfGravity, initialLocation);
                avgDist = (dist1 + dist2)/2;

                if (avgDist < minDistance)
                {
                    correctConfigIndex = i;
                    minDistance = avgDist;
                }
            }

            return new GlintConfiguration(blobs.BlobList[(int) combinations[correctConfigIndex].X],
                                          blobs.BlobList[(int) combinations[correctConfigIndex].Y]);
        }
예제 #8
0
        private GlintConfiguration FilterConfigsBySize(Blobs blobs, List<Point> combinations, GTPoint initialLocation)
        {
            int N = combinations.Count;

            double maxSize = 0;
            double combinationSize;

            int correctConfigIndex = 0;

            for (int i = 0; i < N; i++)
            {
                combinationSize = blobs.BlobList[(int) combinations[i].X].Area +
                                  blobs.BlobList[(int) combinations[i].Y].Area;
                if (combinationSize > maxSize)
                {
                    correctConfigIndex = i;
                    maxSize = combinationSize;
                }
            }

            return new GlintConfiguration(blobs.BlobList[(int) combinations[correctConfigIndex].X],
                                          blobs.BlobList[(int) combinations[correctConfigIndex].Y]);
        }
예제 #9
0
        /// <summary>
        /// Calculates the optimal valid configuration and eliminates the rest of the blobs.
        /// It uses the number of light sources.
        /// </summary>
        public GlintConfiguration GetValidConfiguration(Blobs blobs, GTPoint initialLocation)
        {
            var validConfig = new GlintConfiguration(4);
            var candidateGlintCenters = new Matrix<double>(blobs.Count, blobs.Count);
            Matrix<int> distMatrixThr;
            var combinations = new List<Point>();
            var validConfigurations = new List<GlintConfiguration>();
            var indicesValidConfigs = new List<int>();

            distMatrixThr = GetDistanceMatrix(blobs, MinDistBetweenGlints, MaxDistBetweenGlints);

            for (int i = 0; i < distMatrixThr.Rows; i++)
            {
                combinations.AddRange(GetCombinations(distMatrixThr.GetRow(i).Clone(), i));
            }


            if (combinations.Count > 0)
                validConfig = FilterConfigsByDistance(blobs, combinations, initialLocation);
            else
                validConfig = new GlintConfiguration(1);

            return validConfig;
        }
예제 #10
0
        public Blobs DetectBlobs(Image <Gray, byte> image, int threshold, double minSize, double maxSize, bool isGlint)
        {
            // Detect blobs
            if (isGlint) // Todo: Run recursive blob detection on small ROI images for improved detection/performance
            {
                blobCounter.ProcessImage(image.ThresholdBinary(new Gray(threshold), new Gray(255)));
            }
            else
            {
                blobCounter.ProcessImage(image.ThresholdToZeroInv(new Gray(threshold)));
            }

            // Filtering
            if (isFiltering) // turn off above
            {
                blobCounter.FilterBlobs  = true;
                blobCounter.MinHeight    = (int)minSize;
                blobCounter.MinWidth     = (int)minSize;
                blobCounter.MaxHeight    = (int)maxSize;
                blobCounter.MaxWidth     = (int)maxSize;
                blobCounter.ObjectsOrder = ObjectsOrder.Area;
            }

            // Get blob info
            var blobs = new Blobs(blobCounter.GetObjectsInformation());

            //grahamScan = new GrahamConvexHull();

            // Set blobs properties (edges etc)
            foreach (Blob blob in blobs.BlobDir.Values)
            {
                var leftEdge   = new List <IntPoint>();
                var rightEdge  = new List <IntPoint>();
                var topEdge    = new List <IntPoint>();
                var bottomEdge = new List <IntPoint>();

                // collect edge points
                blobCounter.GetBlobsLeftAndRightEdges(blob, out leftEdge, out rightEdge);
                blobCounter.GetBlobsTopAndBottomEdges(blob, out topEdge, out bottomEdge);

                blobs.leftEdges.Add(blob.ID, leftEdge);
                blobs.rightEdges.Add(blob.ID, rightEdge);
                blobs.topEdges.Add(blob.ID, topEdge);
                blobs.bottomEdges.Add(blob.ID, bottomEdge);

                // find convex hull
                //List<IntPoint> edgePoints = new List<IntPoint>();
                //edgePoints.AddRange(leftEdge);
                //edgePoints.AddRange(rightEdge);

                //List<IntPoint> hull = grahamScan.FindHull(edgePoints);
                //blobs.hulls.Add(blob.ID, hull);

                // find quadrilateral
                //List<IntPoint> quadrilateral = PointsCloud.FindQuadrilateralCorners(hull);
                //blobs.quadrilaterals.Add(blob.ID, quadrilateral);

                //// shift all points for vizualization
                //AForge.IntPoint shift = new IntPoint( 1, 1 );

                //PointsCloud.Shift( leftEdge, shift );
                //PointsCloud.Shift( rightEdge, shift );
                //PointsCloud.Shift( topEdge, shift );
                //PointsCloud.Shift( bottomEdge, shift );
                //PointsCloud.Shift( hull, shift );
                //PointsCloud.Shift( quadrilateral, shift );
            }

            return(blobs);
        }