예제 #1
0
        private int CheckForPattern(TesseractService tess, Mat image, ref double ratioX, ref double ratioY)
        {
            Database       db       = new Database();
            string         SQL      = "SELECT * FROM OCR_2018.dbo.T003_Pattern";
            SqlDataReader  data     = (SqlDataReader)db.Execute(SQL, CONSTANTS.Operation.SELECT);
            List <Pattern> patterns = new List <Pattern>();

            while (data.Read())
            {
                var pat = new Pattern();
                pat.Patter_ID    = (int)data[0];
                pat.Lang         = (string)data[1];
                pat.Resolution_X = (int)data[2];
                pat.Resolution_Y = (int)data[3];
                patterns.Add(pat);
            }
            data.Close();

            foreach (Pattern id in patterns)
            {
                PreviewObject p;
                ratioX = image.Width / id.Resolution_X;
                ratioY = image.Height / id.Resolution_Y;
                if (tess.CheckImageForPatternAndGetDataFromIt(image, GetKeysPossitions(id.Patter_ID, db, true), null, out p, ratioX, ratioY, true))
                {
                    return(id.Patter_ID);
                }
            }

            return(-1);
        }
예제 #2
0
        public void GetConfidence()
        {
            TesseractService tess = new TesseractService(_lang);

            Confidence = tess.GetConfidenceForOrientation(_img, Angle);
            Finished   = true;
        }
예제 #3
0
        public async Task StartService()
        {
            foreach (FileToProcess s in _filesToProcess)
            {
                var progress = new Progress <int>(percent =>
                {
                    if ((s.ProgressBar.Value + percent) > 100)
                    {
                        s.ProgressBar.Value = 100;
                    }
                    else
                    {
                        s.ProgressBar.Value = s.ProgressBar.Value + percent;
                    }
                });
                await Task.Run(async() =>
                {
                    var _cvService = OpenCVImageService.GetInstance();

                    if (SETTINGS.UseGoogleVision)
                    {
                        Annotate anotate = new Annotate();
                        _cvService.PrepareImageForGoogle(s.Path, progress, SETTINGS.TesseractLang);

                        await anotate.GetText(_cvService.Rotated, SETTINGS.GoogleLang, "TEXT_DETECTION");
                        var response    = anotate.Response;
                        PreviewObject p = new PreviewObject();
                        p.Path          = s.Path;
                        p.Lang          = SETTINGS.TesseractLang;
                        p.Img           = _cvService.bmp;
                        p.Lines         = MakeLinesFromWord(response);
                        ProcessLines(p, progress);
                        _previewObjects.Add(p);
                    }
                    else
                    {
                        TesseractService tess = new TesseractService(SETTINGS.TesseractLang);
                        _cvService.PrepareImage(s.Path, progress, SETTINGS.TesseractLang);
                        Mat image     = _cvService.Rotated;
                        double ratioX = 1;
                        double ratioY = 1;
                        var id        = CheckForPattern(tess, image, ref ratioX, ref ratioY);
                        if (id == -1)
                        {
                            PreviewObject p = tess.ProcessImage(image, progress);
                            p.Path          = s.Path;
                            ProcessLines(p, progress);
                            _previewObjects.Add(p);
                        }
                        else
                        {
                            PreviewObject prew;
                            // pattern found => use it
                            tess.CheckImageForPatternAndGetDataFromIt(image, GetKeysPossitions(id), progress, out prew, ratioX, ratioY);
                            prew.Path = s.Path;
                            _previewObjects.Add(prew);
                        }
                    }
                });

                s.ProgressBar.Value = 100;
                s.Button.Enabled    = true;
            }
        }