Esempio n. 1
0
        public IActionResult ProcessFile(IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                return(Content("file not selected"));
            }


            using (var engine = new TesseractEngine(Path.Combine(_environment.WebRootPath, "tessdata"), "eng", EngineMode.Default))
            {
                using (var image = new Bitmap(file.OpenReadStream()))
                {
                    using (var page = engine.Process(image))
                    {
                        IndexViewModel model = new IndexViewModel();
                        model.Text           = page.GetText();
                        model.MeanConfidence = page.GetMeanConfidence();

                        using (var context = new OCRContext())
                        {
                            var a = new Receipt();

                            var b = new AspNetUsers();
                            a.Faktura = model.Text;

                            context.Receipt.Add(a);
                            context.SaveChanges();
                        }

                        return(View("Index", model));
                    }
                }
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> SaveTemplate(string templateName, Region[] regions)
        {
            var imageName = templateName;
            var data      = dbContext.Templates.FirstOrDefault(x => x.TemplateDescription == imageName);

            if (data == null)
            {
                byte[] bytes = System.IO.File.ReadAllBytes(Path.Combine(configSettings.StorageLocation, imageName.Replace("pdf", "png")));
                dbContext.Add(new OcrTemplate(templateName, "Some Data", bytes, JsonSerializer.Serialize(regions, options)));
            }
            else
            {
                data.IdentificationData = JsonSerializer.Serialize(regions, options);
            }
            dbContext.SaveChanges();
            return(Ok());
        }
Esempio n. 3
0
        public ActionResult Create([FromBody] User u)
        {
            using (var context = new OCRContext())
            {
                User test = new User();
                test.Emri = u.Emri;

                context.User.Add(test);
                context.SaveChanges();
            }
            return(View());
        }
Esempio n. 4
0
        public void Next()
        {
            var value = context.Values.FirstOrDefault(f => !f.Verified);

            if (value != null)
            {
                if (!System.IO.File.Exists(value.Location))
                {
                    context.Values.Remove(value);
                    context.SaveChanges();
                    Next();
                    return;
                }
                this.textBox.Text  = value.HashText.Trim();
                this.textBox1.Text = value.Value.Trim();
                BitmapImage i = new BitmapImage();//虽然点了删除,可是图片还显示在窗体里,这时要想重新刷新,给image控件赋值一个空的图片
                i.BeginInit();
                i.StreamSource = System.IO.File.OpenRead(value.Location);
                i.EndInit();
                imageLable.Source = i;
            }
            this.button1.IsEnabled = true;
        }