Esempio n. 1
0
        }//end findListOfMatchingChars

        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)));
        }//end
Esempio n. 2
0
        }//end findListOfListsOfMatchingChars

        public static List <PossibleChar> findListOfMatchingChars(PossibleChar possibleChar, List <PossibleChar> listOfChars)
        {
            List <PossibleChar> listOfMatchingChars = new List <PossibleChar>();

            foreach (PossibleChar possibleMatchingChar in listOfChars)
            {
                if (!possibleMatchingChar.Equals(possibleChar))
                //if (possibleMatchingChar!=possibleChar)
                {
                    //break;//sprobowac jak wyzej


                    double dblDistanceBetweenChars = distanceBetweenChars(possibleChar, possibleMatchingChar);
                    double dblAngleBetweenChars    = angleBetweenChars(possibleChar, possibleMatchingChar);
                    double dblChangeInArea         = Math.Abs(possibleMatchingChar.intRectArea - possibleChar.intRectArea) / possibleChar.intRectArea;


                    double dblChangeInWidth  = Math.Abs(possibleMatchingChar.boundingRect.Width - possibleChar.boundingRect.Width) / possibleChar.boundingRect.Width;
                    double dblChangeInHeight = Math.Abs(possibleMatchingChar.boundingRect.Height - possibleChar.boundingRect.Height) / possibleChar.boundingRect.Height;

                    if (dblDistanceBetweenChars < (possibleChar.dblDiagonalSize * MAX_DIAG_SIZE_MULTIPLE_AWAY) &&
                        dblAngleBetweenChars < MAX_ANGLE_BETWEEN_CHARS &&
                        dblChangeInArea < MAX_CHANGE_IN_AREA &&
                        dblChangeInWidth < MAX_CHANGE_IN_WIDTH &&
                        dblChangeInHeight < MAX_CHANGE_IN_HEIGHT)
                    {
                        listOfMatchingChars.Add(possibleMatchingChar);
                    }
                }
            }
            return(listOfMatchingChars);
        }//end findListOfMatchingChars
Esempio n. 3
0
        }//end

        public static double angleBetweenChars(PossibleChar firstChar, PossibleChar secondChar)
        {
            double dblAdj = (double)(Math.Abs(firstChar.intCenterX - secondChar.intCenterX));
            double dblOpp = (double)(Math.Abs(firstChar.intCenterY - secondChar.intCenterY));

            double dblAngleInRad = Math.Atan(dblOpp / dblAdj);
            double dblAngleInDeg = dblAngleInRad * (180.0 / Math.PI);

            return(dblAngleInDeg);
        }//end
Esempio n. 4
0
        }// end findpossiblecharinplate

        public static bool checkIfPossibleChar(PossibleChar possibleChar)
        {
            if ((possibleChar.intRectArea > MIN_RECT_AREA &&
                 possibleChar.boundingRect.Width > MIN_PIXEL_WIDTH && possibleChar.boundingRect.Height > MIN_PIXEL_HEIGHT &&
                 MIN_ASPECT_RATIO < possibleChar.dblAspectRatio && possibleChar.dblAspectRatio < MAX_ASPECT_RATIO))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }// end checkifpossiblechar
Esempio n. 5
0
        }//end detectcharsinplate

        public static List <PossibleChar> findPossibleCharsInPlate(Mat imgGrayscale, Mat imgThresh)
        {
            List <PossibleChar> listOfPossibleChars = new List <PossibleChar>();

            Mat imgThreshCopy = new Mat();
            VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();

            imgThreshCopy = imgThresh.Clone();

            CvInvoke.FindContours(imgThreshCopy, contours, null, RetrType.List, ChainApproxMethod.ChainApproxSimple);

            for (int i = 0; i <= contours.Size - 1; i++)
            {
                PossibleChar possibleChar = new PossibleChar(contours[i]);

                if (checkIfPossibleChar(possibleChar))
                {
                    listOfPossibleChars.Add(possibleChar);
                }
            }
            return(listOfPossibleChars);
        }// end findpossiblecharinplate
        }//end detectplatesinscene

        public static List <PossibleChar> findPossibleCharsInScene(Mat imgThresh)
        {
            List <PossibleChar> listOfPossibleChars = new List <PossibleChar>();

            Mat imgContours             = new Mat(imgThresh.Size, DepthType.Cv8U, 3);
            int intCountOfPossibleChars = 0;

            Mat imgThreshCopy = imgThresh.Clone();

            VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();

            CvInvoke.FindContours(imgThreshCopy, contours, null, RetrType.List, ChainApproxMethod.ChainApproxSimple);


            for (int i = 0; i < contours.Size - 1; i++)
            {
                //if (frm.IsCheckedSteps() == true)
                //{
                //    CvInvoke.DrawContours(imgContours, contours, i, SCALAR_WHITE);
                //}

                PossibleChar possibleChar = new PossibleChar(contours[i]);

                if (DetectChars.checkIfPossibleChar(possibleChar))
                {
                    intCountOfPossibleChars = intCountOfPossibleChars + 1;
                    listOfPossibleChars.Add(possibleChar);
                }
            }

            //if (frm.IsCheckedSteps() == true)
            //{
            //    CvInvoke.Imshow("2a", imgContours);
            //}
            return(listOfPossibleChars);
        }//end possibleplateinscene