Beispiel #1
0
        public void SaveImgWithContours(Point point)
        {
            var imgToSave = Image;

            foreach (var contour in Contours.ToArrayOfArray())
            {
                var tempVector = new VectorOfPoint(contour);
                CvInvoke.DrawContours(imgToSave, tempVector, 0, new MCvScalar(0, 255, 0), 2);
                var tempRect = CvInvoke.MinAreaRect(tempVector);
                var box      = CvInvoke.BoxPoints(tempRect);
                var boxVec   = new VectorOfPointF(box);
                CvInvoke.DrawContours(imgToSave, boxVec, 0, new MCvScalar(0, 0, 255), 2);
                if (CvInvoke.PointPolygonTest(tempVector, point, true) >= 0)
                {
                    CvInvoke.PutText(ContourImage, tempRect.Size.Height.ToString(CultureInfo.InvariantCulture),
                                     new Point((int)(10 + boxVec[0].X), (int)(10 + boxVec[0].Y)),
                                     FontFace.HersheySimplex, 0.65, new MCvScalar(255, 100, 100, 255), 2);
                }
            }

            var processedDir = FolderName + Path.DirectorySeparatorChar + "processed";

            if (!Directory.Exists(processedDir))
            {
                Directory.CreateDirectory(processedDir);
            }

            CvInvoke.Imwrite(processedDir + Path.DirectorySeparatorChar + OpenedImgNumber + ".jpg", imgToSave);
        }
Beispiel #2
0
 public void DrawAllCellContourSizes()
 {
     foreach (var contour in Contours.ToArrayOfArray())
     {
         var tempVector = new VectorOfPoint(contour);
         var tempRect   = CvInvoke.MinAreaRect(tempVector);
         var box        = CvInvoke.BoxPoints(tempRect);
         var boxVec     = new VectorOfPointF(box);
         CvInvoke.PutText(ContourImage, tempRect.Size.Height.ToString(CultureInfo.InvariantCulture),
                          new Point((int)(10 + boxVec[0].X), (int)(10 + boxVec[0].Y)),
                          FontFace.HersheySimplex, 0.65, new MCvScalar(255, 100, 100, 255), 2);
     }
 }
Beispiel #3
0
 //Returns the length of a cell around a point
 public double GetCellLengthWithContour(Point point)
 {
     foreach (var contour in Contours.ToArrayOfArray())
     {
         var tempVector = new VectorOfPoint(contour);
         if (!(CvInvoke.PointPolygonTest(tempVector, point, true) >= 0))
         {
             continue;
         }
         var tempRect = CvInvoke.MinAreaRect(tempVector);
         return(tempRect.Size.Height);
     }
     return(-1.0);
 }
Beispiel #4
0
        public VectorOfPoint GetContour(Point point)
        {
            VectorOfPoint returnVector = null;

            foreach (var contour in Contours.ToArrayOfArray())
            {
                var tempVector = new VectorOfPoint(contour);
                if (!(CvInvoke.PointPolygonTest(tempVector, point, true) >= 0))
                {
                    continue;
                }
                returnVector = tempVector;
            }

            return(returnVector);
        }
Beispiel #5
0
        private VectorOfPoint GetContourForGivenPoint(Point point)
        {
            var           tempVectorList    = new List <VectorOfPoint>();
            VectorOfPoint tempVectorOfPoint = null;
            var           contArray         = Contours.ToArrayOfArray();

            foreach (var contour in contArray)
            {
                tempVectorOfPoint = new VectorOfPoint(contour);
                if ((CvInvoke.PointPolygonTest(tempVectorOfPoint, point, true) >= 0))
                {
                    tempVectorList.Add(tempVectorOfPoint);
                }
            }
            return(tempVectorOfPoint);
        }
Beispiel #6
0
        public Mat DrawAllCellContourBoundingBoxes()
        {
            var matToReturn         = ContourImage.CreateNewMatLikeThis();
            var boxVecOfVectorPoint = new VectorOfVectorOfPointF();

            foreach (var contour in Contours.ToArrayOfArray())
            {
                var tempVector = new VectorOfPoint(contour);
                var tempRect   = CvInvoke.MinAreaRect(tempVector);
                var box        = CvInvoke.BoxPoints(tempRect);
                var boxVec     = new VectorOfPointF(box);
                boxVecOfVectorPoint.Push(boxVec);
            }

            var convertedVectorOfVectorPoint = boxVecOfVectorPoint.ConvertToVectorOfPoint();

            CvInvoke.DrawContours(matToReturn, convertedVectorOfVectorPoint, -1, new MCvScalar(0, 255, 0, 255), 2);
            return(matToReturn);
        }
Beispiel #7
0
        public Mat DrawAllCellContourBoundingBoxes(Mat imgToMod)
        {
            var matToReturn = imgToMod.CreateNewHardCopyFromMat();

            CvInvoke.CvtColor(matToReturn, matToReturn, ColorConversion.Gray2Bgr);
            var boxVecOfVectorPoint = new VectorOfVectorOfPointF();

            foreach (var contour in Contours.ToArrayOfArray())
            {
                var tempVector = new VectorOfPoint(contour);
                var tempRect   = CvInvoke.MinAreaRect(tempVector);
                var box        = CvInvoke.BoxPoints(tempRect);
                var boxVec     = new VectorOfPointF(box);
                boxVecOfVectorPoint.Push(boxVec);
            }

            var convertedVectorOfVectorPoint = boxVecOfVectorPoint.ConvertToVectorOfPoint();

            CvInvoke.DrawContours(matToReturn, convertedVectorOfVectorPoint, -1, new MCvScalar(0, 255, 0, 255), 2);
            return(matToReturn);
        }
Beispiel #8
0
 public List <(Point, double)> GetAllCellLengthWithCenterPoint()
 {
     return((from contour in Contours.ToArrayOfArray() select new VectorOfPoint(contour) into tempVector let moment = CvInvoke.Moments(tempVector) let cx = moment.M10 / moment.M00 let cy = moment.M01 / moment.M00 let tempPoint = new Point((int)cx, (int)cy) let tempRect = CvInvoke.MinAreaRect(tempVector) select(tempPoint, tempRect.Size.Height)).Select(dummy => ((Point, double))dummy).ToList());
 }
Beispiel #9
0
 public List <double> GetAllCellLength()
 {
     return((from contour in Contours.ToArrayOfArray() select new VectorOfPoint(contour) into tempVector select CvInvoke.MinAreaRect(tempVector) into tempRect select tempRect.Size.Height).Select(dummy => (double)dummy).ToList());
 }