public static ICollection <PossibleChar> FindGroupOfMatchingChars(PossibleChar possibleChar, ICollection <PossibleChar> listOfpossibleChars)
        {
            var vectorOfMatchingChars = new List <PossibleChar>();

            foreach (var possibleMatchingChar in listOfpossibleChars)
            {
                if (possibleMatchingChar.Equals(possibleChar))
                {
                    // then we should not include it in the vector of matches b/c that would end up double including the current char
                    continue;           // so do not add to vector of matches and jump back to top of for loop
                }

                // compute stuff to see if chars are a match
                double dblDistanceBetweenChars = DistanceBetweenChars(possibleChar, possibleMatchingChar);
                double dblAngleBetweenChars    = AngleBetweenChars(possibleChar, possibleMatchingChar);
                double dblChangeInArea         = (double)Math.Abs(possibleMatchingChar.BoundingRectArea - possibleChar.BoundingRectArea) / (double)possibleChar.BoundingRectArea;
                double dblChangeInWidth        = (double)Math.Abs(possibleMatchingChar.BoundingRect.Width - possibleChar.BoundingRect.Width) / (double)possibleChar.BoundingRect.Width;
                double dblChangeInHeight       = (double)Math.Abs(possibleMatchingChar.BoundingRect.Height - possibleChar.BoundingRect.Height) / (double)possibleChar.BoundingRect.Height;

                // check if chars match
                if (dblDistanceBetweenChars < (possibleChar.DblDiagonalSize * Program.MAX_DIAG_SIZE_MULTIPLE_AWAY) &&
                    dblAngleBetweenChars < Program.MAX_ANGLE_BETWEEN_CHARS &&
                    dblChangeInArea < Program.MAX_CHANGE_IN_AREA &&
                    dblChangeInWidth < Program.MAX_CHANGE_IN_WIDTH &&
                    dblChangeInHeight < Program.MAX_CHANGE_IN_HEIGHT)
                {
                    vectorOfMatchingChars.Add(possibleMatchingChar);      // if the chars are a match, add the current char to vector of matching chars
                }
            }

            return(vectorOfMatchingChars);
        }
        public static double DistanceBetweenChars(PossibleChar firstChar, PossibleChar secondChar)
        {
            int intX = Math.Abs(firstChar.IntCenterX - secondChar.IntCenterX);
            int intY = Math.Abs(firstChar.IntCenterY - secondChar.IntCenterY);

            return(Math.Sqrt(Math.Pow(intX, 2) + Math.Pow(intY, 2)));
        }
        public static double AngleBetweenChars(PossibleChar firstChar, PossibleChar secondChar)
        {
            double dblAdj = Math.Abs(firstChar.IntCenterX - secondChar.IntCenterX);
            double dblOpp = Math.Abs(firstChar.IntCenterY - secondChar.IntCenterY);

            double dblAngleInRad = Math.Atan(dblOpp / dblAdj);

            double dblAngleInDeg = dblAngleInRad * (180.0 / Cv2.PI);

            return(dblAngleInDeg);
        }
        private static List <PossibleChar> GetPossibleCharsFromContours(IEnumerable <Point[]> contours, ref Mat imageContours)
        {
            var result = new List <PossibleChar>();

            for (int i = 0; i < contours.Count(); ++i)
            {
                Cv2.DrawContours(imageContours, contours, i, Program.ScalarWhite);
                var possibleChar = new PossibleChar(contours.ElementAt(i));

                if (CheckIfPossibleChar(possibleChar))
                {
                    result.Add(possibleChar);
                }
            }
            return(result);
        }
 public static bool CheckIfPossibleChar(PossibleChar possibleChar)
 => possibleChar.BoundingRectArea > Program.MIN_PIXEL_AREA &&
 possibleChar.BoundingRect.Width > Program.MIN_PIXEL_WIDTH &&
 possibleChar.BoundingRect.Height > Program.MIN_PIXEL_HEIGHT &&
 possibleChar.DblAspectRatio > Program.MIN_ASPECT_RATIO &&
 possibleChar.DblAspectRatio < Program.MAX_ASPECT_RATIO;