Example #1
0
            public static PageOcrData FromPRD(TPage pagePRD)
#endif
            {
                try
                {
                    if (pagePRD != null)
                    {
                        PageOcrData res = new PageOcrData();
                        res.Index = -1;
                        res.Rect  = pagePRD.Rectangle;
                        int li = 0;
                        List <LineOcrData> linesData = new List <LineOcrData>();

                        //-- Iterate PRD data lines --\\
                        foreach (TLine linePRD in pagePRD.Lines)
                        {
                            linesData.Add(new LineOcrData());
                            List <WordOcrData> wordsData = new List <WordOcrData>();
                            int wi = 0;

                            //-- Iterate each line's words --\\
                            foreach (TWord wordPRD in linePRD.Words)
                            {
                                wordsData.Add(new WordOcrData());

                                if (wordPRD.Chars != null && wordPRD.Chars.Count > 0)
                                {
                                    List <CharOcrData> charsData = new List <CharOcrData>();
                                    int ci = 0;

                                    //-- Iterate each word's chars --\\
                                    foreach (TChar charPRD in wordPRD.Chars)
                                    {
                                        //-- Add and define char data --\\
                                        charsData.Add(new CharOcrData());
                                        charsData[charsData.Count - 1].Index      = ci;
                                        charsData[charsData.Count - 1].Confidence = charPRD.Confidance;
                                        charsData[charsData.Count - 1].Rect       = charPRD.Rectangle;
                                        charsData[charsData.Count - 1].Value      = charPRD.CharData;
                                        ci++;
                                    }
                                    if (charsData != null && charsData.Count > 0)
                                    {
                                        wordsData[wordsData.Count - 1].Chars = charsData.ToArray();
                                    }
                                }

                                //-- Define word data --\\
                                wordsData[wordsData.Count - 1].Confidence = wordPRD.Confidance;
                                wordsData[wordsData.Count - 1].Index      = wi;
                                wordsData[wordsData.Count - 1].Rect       = wordPRD.Rectangle;
                                wordsData[wordsData.Count - 1].Style      = wordPRD.Style;
                                wordsData[wordsData.Count - 1].Value      = wordPRD.WordData;
                                wi++;
                            }

                            if (wordsData != null && wordsData.Count > 0)
                            {
                                //-- Define line data --\\
                                linesData[linesData.Count - 1].Confidence = linePRD.Confidance;
                                linesData[linesData.Count - 1].Index      = li;
                                linesData[linesData.Count - 1].Rect       = linePRD.Rectangle;
                                linesData[linesData.Count - 1].Words      = wordsData.ToArray();
                            }
                            li++;
                        }

                        //-- Add the recognized lines to the result --\\
                        if (linesData != null)
                        {
                            res.Lines = linesData.ToArray();
                        }
                        if (res.Lines != null)
                        {
                            return(res);
                        }
                    }
                    else
                    {
                        throw new Exception(String.Format("TPage specified in: [{0}] is not valid", MethodBase.GetCurrentMethod().Name));
                    }
                }
                catch (Exception ex)
                {
                    ILog.LogError(ex);
                }
                return(null);
            }