Beispiel #1
0
        // execute tesseract-OCR
        private string doOcr()
        {
            string _f = getTmpFileNm("base");

            System.IO.File.Delete(_f);
            string _nf = doCorrect(captBmp);

            using (Mat _m = OpenCvSharp.Extensions.BitmapConverter.ToMat(captBmp))
            {
                Mat _mg = new Mat();
                Cv2.CvtColor(_m, _mg, ColorConversionCodes.BGR2GRAY);
                Bitmap _nb = new Bitmap(_mg.Cols, _mg.Rows, (int)_mg.Step(), System.Drawing.Imaging.PixelFormat.Format24bppRgb, _mg.Data);
                gray = (Bitmap)_nb.Clone();
//                Bitmap.UnlockBits(_nb);
            }
            return(OCR.doOcr(_nf, "", 100, 10).Replace("\n", ""));
        }
Beispiel #2
0
        // ----------------------------------------------
        // OKボタン押下
        // ----------------------------------------------
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            Cursor = System.Windows.Input.Cursors.Wait;
            string _lang = ((ComboBoxItem)cmbLanguage.SelectedItem).Content.ToString();

            if (_lang.Equals(string.Empty) || _lang == null)
            {
                _lang = "jpn";
            }
            if (_lang.Equals("jp"))
            {
                _lang = "jpn";
            }
            if (_lang.Equals("en"))
            {
                _lang = "eng";
            }
            string _dir       = this.lbl_Dir.Content.ToString();
            float  _constract = float.Parse(txt_constract.Text);
            float  _sharpe    = float.Parse(txt_sharpe.Text);

            try
            {
                if (!_dir.Equals(string.Empty))
                {
                    string[] _file = getFilePath(_dir);

                    if (_mapResult == null)
                    {
                        _mapResult = new Dictionary <string, string>();
                    }
                    if (_mapView == null)
                    {
                        _mapView = new Dictionary <string, Bitmap>();
                    }

                    foreach (string nm in _file)
                    {
                        dtoOCRResult result      = OCR.doOCRRestApiExecute(_lang: _lang, _filePath: nm, _constract, _sharpe);
                        string       _resultText = OCR.excDtoOcrResultAnalysis(result);

                        tboxResult.Text += "";
                        //entry hashmap
                        if (_mapResult.ContainsKey(nm))
                        {
                            _mapResult[nm] = _resultText;
                            _mapView[nm]   = OCR.ChangeBitmap;
                        }
                        else
                        {
                            _mapResult.Add(nm, _resultText);
                            _mapView.Add(nm, OCR.ChangeBitmap);
                            //ListBox entry
                            lst_Result.Items.Add(nm);
                        }
                    }
                }
                else
                {
                    this.IsEnabled  = false;
                    tboxResult.Text = "";
                    string       language = ((ComboBoxItem)cmbLanguage.SelectedItem).Content.ToString();
                    string       filePath = ((BitmapImage)imgOCR.Source).UriSource.LocalPath;
                    dtoOCRResult result   = OCR.doOCRRestApiExecute(language, filePath, _constract, _sharpe);
                    tboxResult.Text = OCR.excDtoOcrResultAnalysis(result);
                }
            }
            catch (Exception exception)
            {
                tboxResult.Text = exception.Message;
            }
            finally
            {
                this.IsEnabled = true;
                this.Cursor    = System.Windows.Input.Cursors.Arrow;
                Cursor         = null;
            }
        }
Beispiel #3
0
        private void btnAnalysis_Click(object sender, RoutedEventArgs e)
        {
            Cursor = System.Windows.Input.Cursors.Wait;
            if (_mapResult == null)
            {
                _mapResult = new Dictionary <string, string>();
            }
            if (_mapView == null)
            {
                _mapView = new Dictionary <string, Bitmap>();
            }
            string _lan       = ((ComboBoxItem)cmbLanguage.SelectedItem).Content.ToString();
            float  _constract = float.Parse(txt_constract.Text);
            float  _sharpe    = float.Parse(txt_sharpe.Text);

            //言語jpn:eng
            if (_lan.Equals(string.Empty) || _lan == null)
            {
                _lan = "jpn";
            }
            if (_lan.Equals("jp"))
            {
                _lan = "jpn";
            }
            if (_lan.Equals("en"))
            {
                _lan = "eng";
            }
            string _dir = this.lbl_Dir.Content.ToString();

            if (!_dir.Equals(string.Empty))
            {
                string[] _file = getFilePath(_dir);


                foreach (string nm in _file)
                {
                    string _resultText = OCR.doOcr(nm, _lan, _constract, _sharpe);
                    //entry hashmap
                    if (_mapResult.ContainsKey(nm))
                    {
                        _mapResult[nm] = _resultText;
                        _mapView[nm]   = OCR.ChangeBitmap;
                    }
                    else
                    {
                        _mapResult.Add(nm, _resultText);
                        _mapView.Add(nm, OCR.ChangeBitmap);
                        //ListBox entry
                        lst_Result.Items.Add(nm);
                    }
                }
            }
            else
            {
                string _selFilePath = ((BitmapImage)imgOCR.Source).UriSource.LocalPath;
                if (_selFilePath != null && !_selFilePath.Equals(string.Empty))
                {
                    this.tboxResult.Text
                        += "【" + System.IO.Path.GetFileName(_selFilePath) + "】"
                           //                        + CRLF + "result:" + getOCRResult(nm) + CRLF;
                           + CRLF + "result:" + OCR.doOcr(_selFilePath, _lan, _constract, _sharpe) + CRLF;
                    string _newfile = string.Format(@"c:\tool\{0}_{1}.bmp", System.IO.Path.GetFileName(_selFilePath), _constract);
                    if (OCR.ChangeBitmap != null)
                    {
                        OCR.ChangeBitmap.Save(_newfile, ImageFormat.Bmp);
                    }
                    imgOCR.Source = new BitmapImage(new Uri(_newfile, UriKind.RelativeOrAbsolute));
                    OCR.ChangeBitmap.Dispose();
                }
            }
            Cursor = null;
        }