// 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", "")); }
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; }