Ejemplo n.º 1
0
        private async Task <List <string> > Translate()
        {
            List <string> listSource = new List <string>();
            List <string> listTarget = new List <string>();

            if (this.Version == "OCR")
            {
                foreach (OcrResult.Region region in ocrResult.regions)
                {
                    foreach (OcrResult.Line line in region.lines)
                    {
                        listSource.Add(line.TEXT);
                        if (listSource.Count == 25)
                        {
                            List <string> listOutput = await CognitiveServiceAgent.DoTranslate(listSource, Language, "zh-Hans");

                            listTarget.AddRange(listOutput);
                            listSource.Clear();
                        }
                    }
                }
                if (listSource.Count > 0)
                {
                    List <string> listOutput = await CognitiveServiceAgent.DoTranslate(listSource, Language, "zh-Hans");

                    listTarget.AddRange(listOutput);
                }
            }

            return(listTarget);
        }
Ejemplo n.º 2
0
        private async void btn_OCR_Click(object sender, RoutedEventArgs e)
        {
            this.Version  = GetVersion();
            this.Language = GetLanguage();

            if (Version == "OCR")
            {
                ocrResult = await CognitiveServiceAgent.DoOCR(this.tb_Url.Text, Language);

                foreach (OcrResult.Region region in ocrResult.regions)
                {
                    foreach (OcrResult.Line line in region.lines)
                    {
                        if (line.Convert())
                        {
                            Rectangle rect = new Rectangle()
                            {
                                Margin = new Thickness(line.BB[0], line.BB[1], 0, 0),
                                Width  = line.BB[2],
                                Height = line.BB[3],
                                Stroke = Brushes.Red,
                                //Fill =Brushes.White
                            };
                            this.canvas_1.Children.Add(rect);
                        }
                    }
                }
            }
            else
            {
                newOcrResult = await CognitiveServiceAgent.DoRecognizeText(this.tb_Url.Text);

                // 1 - erase the original text
                foreach (NewOcrResult.Line line in newOcrResult.recognitionResult.lines)
                {
                    Polygon         p  = new Polygon();
                    PointCollection pc = new PointCollection();
                    pc.Add(new Point(line.boundingBox[0], line.boundingBox[1]));
                    pc.Add(new Point(line.boundingBox[2], line.boundingBox[3]));
                    pc.Add(new Point(line.boundingBox[4], line.boundingBox[5]));
                    pc.Add(new Point(line.boundingBox[6], line.boundingBox[7]));
                    p.Points = pc;
                    p.Stroke = Brushes.Red;
                    this.canvas_1.Children.Add(p);
                }
            }
        }