Пример #1
0
        public string Parse(RecognizedPlate recognizedPlate, int syntaxAnalysisMode)
        {
            if (syntaxAnalysisMode == 0)
            {
                Program.ReportGenerator.InsertText(" result : " + recognizedPlate.GetString() + " --> <font size=15>" +
                                                   recognizedPlate.GetString() + "</font><hr><br>");
                return(recognizedPlate.GetString());
            }

            int length = recognizedPlate.Chars.Count;

            UnFlagAll();
            if (syntaxAnalysisMode == 1)
            {
                FlagEqualLength(length);
            }
            else
            {
                FlagEqualOrShorterLength(length);
            }

            List <FinalPlate> finalPlates = new List <FinalPlate>();

            foreach (PlateForm form in _plateForms)
            {
                if (!form.Flagged)
                {
                    continue;
                }
                for (int i = 0; i <= length - form.Length(); i++)
                {
                    FinalPlate finalPlate = new FinalPlate();
                    for (int ii = 0; ii < form.Length(); ii++)
                    {
                        CharacterRecognizer.RecognizedChar rc = recognizedPlate.GetChar(ii + i);

                        if (form.GetPosition(ii).IsAllowed(rc.GetPattern(0).Character))
                        {
                            finalPlate.AddChar(rc.GetPattern(0).Character);
                        }
                        else
                        {
                            finalPlate.RequiredChanges++;
                            for (int x = 0; x < rc.Patterns.Count; x++)
                            {
                                if (!form.GetPosition(ii).IsAllowed(rc.GetPattern(x).Character))
                                {
                                    continue;
                                }
                                CharacterRecognizer.RecognizedChar.RecognizedPattern rp = rc.GetPattern(x);
                                finalPlate.RequiredChanges += (rp.Cost / 100);
                                finalPlate.AddChar(rp.Character);
                                break;
                            }
                        }
                    }
                    finalPlates.Add(finalPlate);
                }
            }
            if (finalPlates.Count == 0)
            {
                return(recognizedPlate.GetString());
            }
            float minimalChanges = float.PositiveInfinity;
            int   minimalIndex   = 0;

            for (int i = 0; i < finalPlates.Count; i++)
            {
                if (!(finalPlates.ElementAt(i).RequiredChanges <= minimalChanges))
                {
                    continue;
                }
                minimalChanges = finalPlates.ElementAt(i).RequiredChanges;
                minimalIndex   = i;
            }

            string toReturn = recognizedPlate.GetString();

            if (finalPlates.ElementAt(minimalIndex).RequiredChanges <= 2)
            {
                toReturn = finalPlates.ElementAt(minimalIndex).Plate;
            }
            return(toReturn);
        }
Пример #2
0
        public String Parse(RecognizedPlate recognizedPlate, Int32 syntaxAnalysisMode)
        {
            Int32 length = recognizedPlate.GetChars.Count;

            UnFlagAll();
            FlagEqualOrShorterLength(length);

            List <FinalPlate> finalPlates = new List <FinalPlate>();

            foreach (PlateForm form in plateForms)
            {
                if (!form.flagged)
                {
                    continue;
                }

                for (Int32 i = 0; i <= length - form.Length; i++)
                {
                    FinalPlate finalPlate = new FinalPlate();
                    for (Int32 ii = 0; ii < form.Length; ii++)
                    {
                        CharacterRecognizer.RecognizedChar rc = recognizedPlate.GetChar(ii + i);

                        if (form.GetPosition(ii).IsAllowed(rc.GetPattern(0).GetChar))
                        {
                            finalPlate.AddChar(rc.GetPattern(0).GetChar);
                        }
                        else
                        {
                            finalPlate.IncrementRequiredChanges();
                            for (Int32 x = 0; x < rc.GetPatterns().Count; x++)
                            {
                                if (form.GetPosition(ii).IsAllowed(rc.GetPattern(x).GetChar))
                                {
                                    CharacterRecognizer.RecognizedChar.RecognizedPattern rp = rc.GetPattern(x);
                                    finalPlate.AddRequiredChanges(rp.GetCost / 100.0);
                                    finalPlate.AddChar(rp.GetChar);
                                    break;
                                }
                            }
                        }
                    }

                    finalPlates.Add(finalPlate);
                }
            }

            if (finalPlates.Count == 0)
            {
                return(recognizedPlate.GetString());
            }

            Double minimalChanges = Double.PositiveInfinity;
            Int32  minimalIndex   = 0;

            for (Int32 i = 0; i < finalPlates.Count; i++)
            {
                if (finalPlates[i].RequiredChanges <= minimalChanges)
                {
                    minimalChanges = finalPlates[i].RequiredChanges;
                    minimalIndex   = i;
                }
            }

            String toReturn = recognizedPlate.GetString();

            if (finalPlates[minimalIndex].RequiredChanges <= 2)
            {
                toReturn = finalPlates[minimalIndex].GetPlate();
            }

            return(toReturn);
        }