Esempio n. 1
0
 private void RecognitionOutput(IRecognitionResult result, string imageName)
 {
     dataGridViewResult.DataSource = result.Items;
     picBx.Image = result.DrawBorder2Image();
     imageLogger = new ImageLogger(result, imageName);
     imageLogger.Save($@"Results/{imageName}.json");
 }
Esempio n. 2
0
        public static void SaveToJson(this IRecognitionResult result, string path, string imageName)
        {
            var index = 0;

            foreach (var item in result.Items)
            {
                var xc = item.X;
                var yc = item.Y;
                var w  = item.Width;
                var h  = item.Height;

                var jsonObject = new RecognitionResultJsonObject
                {
                    ImageName = imageName,
                    Team      = Constants.TeamName,
                    Region    = new Region
                    {
                        Main = new Main
                        {
                            TopLeft = new int[] { xc - w / 2, yc + h / 2 }.ToList(),
                    BotRight = new int[] { xc + w / 2, yc - h / 2 }.ToList(),
                        },
                        Alternative = new Alternative
                        {
                            Center = new int[] { xc, yc }.ToList(),
                    Height = h,
                    Width  = w,
                        },
                        EachPoint = new EachPoint[]
                        {
                            new EachPoint
                            {
                                Comment = "top-left, (x; y)",
                                Point   = new int[] { xc - w / 2, yc + h / 2 }.ToList(),
                            },
                            new EachPoint
                            {
                                Comment = "top-right, (x; y)",
                                Point   = new int[] { xc + w / 2, yc + h / 2 }.ToList(),
                            },
                            new EachPoint
                            {
                                Comment = "bottom-right, (x; y)",
                                Point   = new int[] { xc + w / 2, yc - h / 2 }.ToList(),
                            },
                            new EachPoint
                            {
                                Comment = "bottom-left, (x; y)",
                                Point   = new int[] { xc - w / 2, yc - h / 2 }.ToList(),
                            },
                        }.ToList()
                    }
                };

                Save(path, imageName, index++, jsonObject);
            }
        }
Esempio n. 3
0
        private void RecognizeButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.FilePath))
            {
                // Console.WriteLine(string.Join("\r\n", Directory.EnumerateFiles("./")));
                using (TesseractEngine engine = new TesseractEngine(@"./tessdata", "rus", EngineMode.TesseractAndLstm))
                {
                    IRecognitionResult result = TessEngineWrapper.ReadFile(this.Pix, engine);

                    SetMeanConfidence(result.MeanConfidence);
                    DecodedText.Text = result.Text;
                }
            }
        }
Esempio n. 4
0
        public static Image DrawBorder2Image(this IRecognitionResult result)
        {
            var image = result.ImageBytes.ToImage();

            using (var canvas = Graphics.FromImage(image))
            {
                foreach (var item in result.Items)
                {
                    using (var pen = new Pen(Brushes.GreenYellow, image.Width / 100))
                    {
                        canvas.DrawRectangle(pen, item.X, item.Y, item.Width, item.Height);
                        canvas.Flush();
                    }
                }
            }
            return(image);
        }
Esempio n. 5
0
 public ImageLogger(IRecognitionResult result, string imageName)
 {
     obj           = new RootObject();
     obj.ImageName = imageName;
     obj.Team      = "team6";
     foreach (var item in result.Items)
     {
         var xc = item.X;
         var yc = item.Y;
         var w  = item.Width;
         var h  = item.Height;
         obj.Region              = new Region();
         obj.Region.Main         = new Main();
         obj.Region.Main.TopLeft = new List <int> {
             (xc - w / 2), (yc + h / 2)
         };
         obj.Region.Main.BotRight = new List <int> {
             (xc + w / 2), (yc - h / 2)
         };
         obj.Region.Alternative        = new Alternative();
         obj.Region.Alternative.Center = new List <int> {
             xc, yc
         };
         obj.Region.Alternative.Width  = w;
         obj.Region.Alternative.Height = h;
         obj.Region.EachPoint          = new List <EachPoint> {
             new EachPoint("top-left, (x; y)", new List <int> {
                 (xc - w / 2), (yc + h / 2)
             }),
             new EachPoint("top-right, (x; y)", new List <int> {
                 (xc + w / 2), (yc + h / 2)
             }),
             new EachPoint("bottom-right, (x; y)", new List <int> {
                 (xc + w / 2), (yc - h / 2)
             }),
             new EachPoint("bottom-left, (x; y)", new List <int> {
                 (xc - w / 2), (yc - h / 2)
             })
         };
     }
 }