예제 #1
0
        public void Update()
        {
            var output = new DrawingGroup();
            var format = new BasicTextParagraphProperties("Times New Roman", 34, FlowDirection.LeftToRight);
            var words = BoundedWord.GetWords(Text, Measurer.MeasureLines(Text, 200, format, output)).ToList();
            Image = output.ToBitmap();

            ImageData imageData;
            using (var stream = Image.CreateStream())
                imageData = new ImageData(stream);

            var boards = imageData.DefineIteratedBoards();
            var chars = words.SelectMany(w => w.Characters);
            Segments = chars.Select(boards.GetLetterHeuristics).ToList();
        }
예제 #2
0
        public Stream CreateImage(string html)
        {
            if (String.IsNullOrWhiteSpace(html))
                return new RenderTargetBitmap(Width, 1, 0, 0, PixelFormats.Pbgra32).CreateStream();

            string text = HttpUtility.HtmlDecode(html);

            var output = new DrawingGroup();
            var format = new BasicTextParagraphProperties(font, 14, FlowDirection.RightToLeft);
            var words = Measurer.MeasureLines(text, Width, format, output).ToList();

            var dv = new DrawingVisual();
            using (var c = dv.RenderOpen())
                c.DrawImage(new DrawingImage(output), new Rect(new Point(Width - output.Bounds.Width, 0), output.Bounds.Size));
            var rtb = new RenderTargetBitmap(Width, (int)output.Bounds.Height, 96, 96, PixelFormats.Pbgra32);
            rtb.Render(dv);

            return rtb.CreateStream();
        }
예제 #3
0
파일: Program.cs 프로젝트: Amichai/Prax
        static void Main(string[] args)
        {
            string fileName = @"C:\Users\Public\Pictures\temp.png";
            string renderMe = "تلبستبي بيسا سي";
            var output = new DrawingGroup();
            BasicTextParagraphProperties format = new BasicTextParagraphProperties("Tahoma", 13, FlowDirection.LeftToRight);
            var segments = TextSegment.GetWords(renderMe, Measurer.MeasureLines(renderMe, 200, format, output)).ToList();
            output.ToBitmap().CreateStream(fileName).Close();
            Document uploadDocument = new Document(fileName);

            //List<string> wordsRendered = renderMe.Split(' ').ToList();
            //List<CharacterBounds> boundsForeachWord = new List<CharacterBounds>();
            //foreach (var word in wordsRendered) {
            //    boundsForeachWord.Add(new CharacterBounds(segments, word));
            //}
            //IteratedBoards boards = uploadDocument.DefineIteratedBoards();
            ////TrainingData trainingData;
            ////foreach (var word in boundsForeachWord) {
            ////    trainingData = boards.Train(word);
            ////}
            //foreach (var testBoard in boards.Segment()) {}
        }
예제 #4
0
        public void TestAlgorithm()
        {
            string renderText = "أدخل نص هنا لترجمة";
            //string renderText = "أد";
            //string renderText = "ﺀﺁﺂﺃﺄﺅﺆﺇﺈﺉﺊﺋﺌﺍﺎﺏﺐﺑﺒﺓﺔﺕﺖﺗﺘﺙﺚﺛﺜﺝﺞﺟﺠﺡﺢﺣﺤﺥﺦﺧﺨﺩﺪﺫﺬﺭﺮﺯﺰﺱﺲﺳﺴﺵﺶﺷﺸﺹﺺﺻﺼﺽﺾﺿﻀﻁﻂﻃﻄﻅﻆﻇﻈﻉﻊﻋﻌﻍﻎﻏﻐﻑﻒﻓﻔﻕﻖﻗﻘﻙﻚﻛﻜﻝﻞﻟﻠﻡﻢﻣﻤﻥﻦﻧﻨﻩﻪﻫﻬﻭﻮﻯﻰﻱﻲﻳﻴﻵﻶﻷﻸﻹﻺﻻﻼ";
            //string renderText = "ﺬﻤﺈﺗﻹﻕﻐﻘﻝﺺﻔﺒﺭﻧﻂﺓﻫﻲﺸﺪﺊﻭﻜﺶﻆﻸﻒﺆﺄﻤﻴﺣﻄﻗﻖﺹﺶﺅﺆﺔﻣﻕﻨﺝﻓﻂﺭﺡﺀﻷﺣﺜﻷﻞﺶﺼﺈﻎﻍﺁﺂﻊﻓﻶﻃﺰﻊﻒﺑﺈﻙﻦﻬﺣﻃﺲﺄﺿﻠﺄﻊﺰﺆﺊﻁﻗﺨﻣﺡﺚﺱﻤﺴﺄﺑﺙﺂﻮﻖﺢﻴﻘﺐﻴﺞﺹﺬﻔﺛﺄﺷﻅﻫﻈﺳﻎﻃﻉﺵﻨﺇﻤﺱﻴﻔﻱﺲﻨﺑﺩﺯﺒﻥﺽﺍﻯﺠﺏﻨﺇﺫﻑﻈﺜﻟﻨﻶﻨﻎﻀﻒﺵﺹﻫﺚﺏﺧﺙﺟﺪﺇﻁﻂﻮﻑﺤﻝﺭﺻﻁﺮﺴﻝﺭﺽﺳﺛﺔﺔﻩﻸﻆﺙﻎﻓﻶﻖﻷﺣﻺﻇﺇﻬﺾﺀﻦﺎﻖﻈﺻﺋﻈﺭﺌﺑﺞﻕﺋﺮﻤﻱﺒﺅﺳﺮﺽﺨﻱﺛﻗﻊﻣﺊﺽﻶﺧﻄﺞﺭﻔﺤﻁﻉﻕﻝﺯﺘﺌﺼﺴﺡﻊﻈﺼﺉﺵﺁﺹﺏﺿﺾﺚﺻﻭﻭﺥﺽﻬﺓﻧﻗﺷﻚﻗﺿﺯﻅﺬﻒﻼﺥﺛﺴﻣﺶﻼﺚﻋﺳﻁﺥﺊﺎﻫﺕﺊﺆﻙﻥﺸﻯﺨﻶﻒﻚﻧﻭﻮﻹﻗ";

            var output = new DrawingGroup();
            var format = new BasicTextParagraphProperties("Times New Roman", 14, FlowDirection.LeftToRight);
            var words = BoundedWord.GetWords(renderText, Measurer.MeasureLines(renderText, 200, format, output)).ToList();

            //using (var stream = output.ToBitmap().CreateStream()) {
            using (var stream = File.OpenRead(@"C:\Users\SSL\Temp\Arabic.png")) {
                //using (var targetStream = File.Create(@"C:\Users\SSL\Temp\Arabic-Console.png"))
                //    stream.CopyTo(targetStream);

                stream.Position = 0;

                var imageData = new ImageData(stream);
                stream.Position = 0;

                //System.Drawing.Bitmap b = boards.Boards.First().Matrix.ExtractRectangularContentArea(segment.Bounds).ConvertDoubleArrayToBitmap(System.Drawing.Color.White);
                //whitespaceResults.Last().Log(boards.Boards.First().Matrix.ExtractRectangularContentArea(segment.Bounds).ConvertDoubleArrayToBitmap(System.Drawing.Color.White));

                //characterResults.Last().Log(boards.Boards.First().Matrix.ExtractRectangularContentArea(segment.Bounds).ConvertDoubleArrayToBitmap(System.Drawing.Color.White));
                //Debug.Print(characterResults.Last().Text + " " + characterResults.Last().Certainty.ToString());

                var trainingData = new MutableReferenceSet();
                trainingData.ReadFrom(trainingFolder);
                var searcher = new ReferenceSearcher(trainingData);
                var recognizer = new OriginalDocumentRecognizer(searcher);

                var reporter = new ConsoleProgressReporter(false);
                var results = recognizer.Recognize(stream, reporter).ToList().AsReadOnly();

                var outputString = new StreamReader(OutputRenderer.PlainText.Convert(stream, results)).ReadToEnd();
                Debug.Print(outputString);
            }
        }
예제 #5
0
        //TODO: Test for white space first
        public void TrainAlgorithm()
        {
            string renderText = "أدخل نص هنا لترجمة";
            //string renderText = "ﻂﺎﺉﻳﺕﺍﻈﺕﻊﺹﻫﻑﻈﻂﻟﺐﺻﺔﺛﺅﺡﺽﻛﻟﺊﺒﻖﺼﻞﺫﻳﺀﺎﻠﻜﻯﺛﺠﻔﺡﺜﺠﻹﺡﺕﺨﺜﻛﻃﺜﺗﺯﺘﺈﻞﺄﺰﺦﻨﺂﺳﺋﺳﺟﻃﻪﻃﻤﻣﻭﻱﺚﺽﻷﻦﺁﻁﺹﻊﻞﻲﻷﻶﻁﺓﻃﻥﺅﺂﻗﺿﻲﺵﻑﻪﺐﻩﻚﻛﺧﻢﺵﻵﻓﺨﻹﻯﺝﺟﻝﺿﻳﻘﺉﺌﺸﺒﻮﺋﻼﺅﺽﻢﺋﺭﻻﻢﻨﺍﻕﺔﻤﻛﺢﻹﺽﺂﺣﺙﺖﻑﻇﻣﺢﺘﻈﺙﺫﻄﺱﻺﻷﻎﻛﺢﺥﻏﻩﺥﺩﺗﺇﺐﻆﻈﻘﺘﺶﺍﻌﺶﻬﻕﻱﺫﺺﻖﻀﻰﻢﻡﺶﺣﻘﻗﺙﺖﻼﻼﻔﻫﺕﻺﻬﻼﻉﺶﺜﻖﺼﺰﻠﺞﻵﻸﺎﺢﻙﺯﻤﻋﺏﻵﺿﻄﻝﻡﺵﻬﺯﻂﺘﺶﺵﻞﺠﻮﻥﻱﻟﺄﺺﻦﺳﺲﺁﺘﺪﻜﻉﻴﺹﻍﺘﺉﻛﺜﺻﺧﺟﻥﺁﺭﺧﻷﺗﺪﻥﺗﻗﺜﺹﻥﻍﻠﺐﺥﻂﺍﻃﻅﺶﻕﺣﺸﺈﻇﺞﺬﺂﺃﺳﺽﻒﻶﺃﺌﺿﺸﺚﻓﺯﺒﺄﺬﺺﻐﺀﺴﻵﺶﻗﺭﻡﻗﺮﺨﺊﻫﻯﻌﺌﺹﺕﻔﻦﻸﺒﻓﻝﺄﻢﺉﻯﻬﺕﺤﻐﻳﻺﺵﻇﻦﺴﻉﺨﺅﻙﻷﻇﻗﺂﻐﻆﻊﻇﻲﻺﺭﻃﺾﺽﺩﻓﻰﻐﻎﺺﻱﻁﺊﻕﺓﻭﺺﺅﺢﺄﻈﺫﻠﺟﺘﺌﺆﺂﺑﺿﺤﺤﺟﺦﺣﺰﺼﻴﺞﺒﻀﻶﻗﻇﻤﺶﺼﺂﻫﻟﺌﻅﺥﻮﺱﺁﻟﺟﺥﺝﻍﻮﺾﺎﺖﻌﺡﻠﺱﻠﺱﻂﻣﺏﻁﻏﻐﺘﺷﻞﻌﺃﺓﺮﺳﻜﻼﺮﻲﺡﻍﺝﻎﺀﻂﻎﺷﻉﺱﺘﺔﻙﻍﺊﺮﻆﻞﺕﺭﻞﺭﻇﻤﻃﻍﻉﻛﺏﻗﺶﻍﻯﻫﺐﺒﺔﻱﻢﻊﻯﺗﺇﻣﺞﻉﻰﺳﺉﺀﻩﻺﻦﺁﺓﻰﺆﺵﺊﺰﻵﻰﺨﻮﻷﻈﺢﻪﺽﻴﺚﻒﻸﻈﺺﻆﺦﻠﻅﻶﻚﺖﻑﺏﻫﺹﻣﻮﻗﺜﺌﻛﻧﺲﻒﻻﻬﺕﻨﻓﺧﺅﻳﺑﻣﺗﺁﺞﻄﻉﻉﺢﻬﺐﻒﻞﺞﺘﺃﺾﻡﺱﺒﺠﻨﺻﻨﻅﻲﺻﻗﺑﻵﻯﻏﻔﺟﻀﺩﻓﺷﻄﺩﺎﻐﻦﻬﻖﻝﻰﻜﻓﺒﺪﻮﻳﻰﻓﺦﺧﺬﺸﺨﺈﻯﺸﺪﻺﺾﻺﺾﻛﻬﺬﺆﺝﺇﺄﻍﺁﻋﺑﻥﺂﻜﺃﻻﻊﺀﻘﻡﻉﺚﺁﺧﻻﺛﺡﺛﺗﺼﻯﺘﻠﺱﺁﻤﻣﺣﻑﻬﻫﺆﺤﻘﺚﻐﺦﺩﻬﺺﻜﻺﻢﺘﻲﻀﻫﺄﺇﺁﻢﻦﺵﻁﻙﻶﺄﻍﻚﺛﺘﺧﺫﻨﻳﻃﻲﺥﺌﺫﻱﻵﺫﻚﻜﻲﺲﻇﺼﺽﻵﻞﺛﻐﺊﺅﻍﻠﻻﺡﻌﻖﻋﻐﺡﺵﻎﻷﺢﺮﻋﻅﻴﻙﺌﻩﺺﻘﻢﻤﻃﺹﺐﺜﺣﺷﺋﻘﻞﻭﻳﺒﺦﻨﻜﺛﺪﻘﺸﺧﺣﺸﺥﺎﻯﺰﻦﺿﻃﺝﻈﻱﻺﺗﻚﺒﻅﺯﺭﻧﺩﻳﺘﺲﺷﺸﺞﺌﻺﻭﺿﻞﺠﺺﻁﺋﺔﺂﺩﻯﻍﻉﺕﻀﺤﺂﺔﺏﺍﻊﻓﻷﺪﻍﻻﺭﺟﻰﻓﺷﺒﻚﻂﻒﻛﻦﻑﻀﻓﻏﻺﻂﺅﺺﺚﻝﻞﻕﺍﺵﺣﺎﻼﺰﺚﻄﺴﻏﺼﺓﻨﺡﺫﻯﻝﻰﺇﺿﻢﺻﺮﻑﺹﺻﻌﺐﻲﻬﺳﺝﻌﻇﻢﺞﺓﺃﻛﺒﺸﺗﺲﺁﺃﺿﻣﻘﺖﺒﻚﺦﻖﺞﻯﻏﺇﻏﻒﻁﻠﺉﻎﻄﺛﺞﻄﺡﺼﺍﻜﻚﺕﻲﺇﻊﺈﺬﻍﻷﻔﻱﻷﻠﺒﺌﻄﺭﻔﺓﺖﻀﺮﺙﺮﺯﻅﻫﻢﻢﻷﻂﺜﺉﺳﺀﺑﻡﺗﺥﻆﻘﺁﻗﻩﻫﺏﻫﺲﺎﻗﺗﻉﺨﻳﺛﺫﻸﻃﻕﺅﺚﻆﻨﻼﺑﻔﻭﺬﺑﻸﻠﺖﺯﻉﺻﺾﻓﺭﻀﺟﻖﺸﻔﺊﻠﻶﻰﺒﺗﻑﺖﺝﺿﺟﺬﺑﺖﻗﻘﺖﺞﺾ";
            var output = new DrawingGroup();
            var format = new BasicTextParagraphProperties("Times New Roman", 14, FlowDirection.LeftToRight);
            var words = BoundedWord.GetWords(renderText, Measurer.MeasureLines(renderText, 200, format, output)).ToList();
            var stream = output.ToBitmap().CreateStream();
            var imageData = new ImageData(stream);
            imageData.SaveFile("RenderedFile1.png");
            stream.Close();

            Directory.CreateDirectory(trainingFolder);

            var boards = imageData.DefineIteratedBoards();
            var trainingData = new MutableReferenceSet();

            //ADD TO EXISTING TRAINING DATA LIBRARY:
            //trainingData.ReadFrom(trainingFolder);

            var characters = words.SelectMany(w => w.Characters).ToList();
            for (int i = 0; i < characters.Count(); i++) {
                var ch1 = characters[i];
                var letterHeuristics = boards.GetLetterHeuristics(ch1);
                if (i < characters.Count() - 1) {
                    var ch2 = characters[i + 1];
                    var whitespaceHeuristics = boards.GetSpaceHeuristics(ch1, ch2);
                    trainingData.AddHeuristics(whitespaceHeuristics);
                }
                if (letterHeuristics != null)
                    trainingData.AddHeuristics(letterHeuristics);
            }
            ImageUtilities.Utilities.TrainingLog.ToString();

            trainingData.WriteTo(trainingFolder);
        }