コード例 #1
0
ファイル: Segmenter.cs プロジェクト: Adriano1984/VistaLink
        public VidiReadResults.VidiReadResults[] GenerateVidiReadResults(SegmentInput Input, int StartIndex, int EndIndex, double devP)
        //Generate array of ViDiReadResults
        {
            DoublesRemoved dblsRemoved = RemoveDoubles(Input, StartIndex, EndIndex, devP);
            int            n           = dblsRemoved.DbleRemovedStr.Length;

            VidiReadResults.VidiReadResults[] results = new VidiReadResults.VidiReadResults[n];
            if (n > 0)
            {
                try
                {
                    int j = 0;
                    while (j < n)
                    {
                        VidiReadResults.VidiReadResults res = new VidiReadResults.VidiReadResults('0', 0, 0)
                        {
                            Character = dblsRemoved.CharList[j],
                            Score     = dblsRemoved.ScoreList[j],
                            Position  = dblsRemoved.PosList[j]
                        };
                        results[j] = res;
                        j++;
                    }
                }
                catch { }
            }

            return(results);
        }
コード例 #2
0
ファイル: Segmenter.cs プロジェクト: Adriano1984/VistaLink
        public DoublesRemoved RemoveDoubles(SegmentInput Input, int StartIndex, int EndIndex, double devP)
        //Code to remove double characters at the same position based on the score
        {
            DoublesRemoved result = new DoublesRemoved();

            IBlueMarking m   = Input.Marking;
            int          n   = (EndIndex + 1);
            string       ocr = Input.OcrString;
            Point        p   = new Point();

            char[]      ocr_char     = ocr.ToCharArray();         //string[int] is read-only--> create and modify the character array and convert back to string
            List <char> char_list    = new List <char>(ocr_char); //Convert to List to be able to easily remove at certain position
            List <char> newChar_list = new List <char>();         //list to build new string (no doubles)

            List <double> score_list = new List <double>();       //list for score (to build result array later)
            List <double> pos_list   = new List <double>();       //list for positions (to build result array later)

            double w          = 0;                                //Char width
            double dev        = devP;                             //consider same when difference between two positions is < dev * characterwidth
            double x_curr     = 0;
            double x_prev     = 0;
            double score_prev = 0;
            double score_curr = 0;

            try
            {
                if (m != null && n > 1)                                            //Marking present and at least 2 characters
                {
                    int i = StartIndex;                                            //index in Marking
                    int j = 0;                                                     //index for newChar_list
                    while (i < n)                                                  //loop trough all of characters
                    {
                        w          = m.Views[0].Matches[0].Features[i].Size.Width; //Get char width
                        p          = m.Views[0].Matches[0].Features[i].Position;
                        p          = p.ToOriginalFromView(m.Views[0]);
                        x_curr     = p.X;
                        score_curr = m.Views[0].Matches[0].Features[i].Score;

                        if (((x_curr - x_prev) < (dev * w)) && (j > 0)) //Compare scores when two char at one position (but not for 1st index of loop)
                        {
                            if (score_curr >= score_prev)
                            {
                                newChar_list.RemoveAt(j - 1);
                                score_list.RemoveAt(j - 1);
                                pos_list.RemoveAt(j - 1);

                                newChar_list.Add(char_list[j]);
                                score_list.Add(score_curr);
                                pos_list.Add(x_curr);
                            }
                            else
                            {
                                //Niks doen (niet toevoegen aan list)
                            }
                        }
                        else
                        {
                            newChar_list.Add(char_list[j]);
                            score_list.Add(score_curr);
                            pos_list.Add(x_curr);
                        }
                        x_prev     = x_curr;
                        score_prev = score_curr;
                        i++;
                        j++;
                    }
                    ocr_char = newChar_list.ToArray();
                    result.DbleRemovedStr = ocr = new string(ocr_char);
                }
                else
                {
                    result.DbleRemovedStr = "";
                }

                result.CharList  = newChar_list;
                result.PosList   = pos_list;
                result.ScoreList = score_list;
            }
            catch  { result.DbleRemovedStr = ""; }

            return(result);
        }